Skip to content

Update docs for unique #41

@kmalakoff

Description

@kmalakoff

$unique docs

Common

  • $unique with $sort
    • Rows will contain values for the first entry matching the $unique field sorted by the $sort query.
  • $unique with $count
    • All other queries are ignored and the count of rows after grouping by the $unique fields is returned.

backbone-sql

$unique uses postgres specific functions for some functionality.

  • $unique without specifying $select or $values:
    • The documents returned will contain fields for each column. This uses postgres window functions and will not work with mysql.
  • $unique with $select or $values when $select or $values contain fields not in $unique.
    • The documents returned will contain fields for each field in ($select or $values). This uses postgres window functions and will not work with mysql.
  • $unique with $select or $values when $select or $values do not contain fields not in $unique.
    • As above, but an sql distinct query is used. This will work with mysql, etc.
  • $unique without $sort
    • Rows will contain values for the first entry matching the $unique field. The 'first entry' is the first when rows are sorted by id.

backbone-mongo

$unique uses the mongodb aggregation framework. There are limitations involved, so results are a bit different than with postgres.

  • $unique without specifying $select or $values:
    • This will only return the id field and the fields specified in $unique.
  • $unique with $select or $values:
    • The document returned with have each field in $select or $values.
  • $unique without $sort
    • Rows will contain values for the first entry matching the $unique field. The 'first entry' is random without a $sort query. Don't do this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions