Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update docs for unique #41

Open
kmalakoff opened this issue Aug 1, 2014 · 0 comments
Open

Update docs for unique #41

kmalakoff opened this issue Aug 1, 2014 · 0 comments

Comments

@kmalakoff
Copy link
Member

$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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant