Skip to content

Commit

Permalink
final: added omit query to set a projection that omits fields instead…
Browse files Browse the repository at this point in the history
… of selecting fields (as the field query does)
  • Loading branch information
rbarkas committed Sep 2, 2015
1 parent 444068c commit 8ebb073
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ For example, a query such as: `name=john&age>21&omit=name&sort=name,-age&offset=
{
criteria: {
name: 'john',
age: { $gt: 21 }
age: { $gt: 21 }
},
options: {
fields: { name: false },
Expand Down Expand Up @@ -105,7 +105,7 @@ The _fields_ argument is a comma separated list of field names to include in the

The _omit_ argument is a comma separated list of field names to exclude in the results. For example `omit=name,age` results in a _option.fields_ value of `{'name':false,'age':false}`. If no fields are specified then _option.fields_ is null, returning full documents as results.

Note that either _fields_ or _omit_ can be used. If both are specified then _omit_ takes precedence and the _fields_ entry is ignored. Mongo will not accept a mix true and false fields
Note that either _fields_ or _omit_ can be used. If both are specified then _omit_ takes precedence and the _fields_ entry is ignored. Mongo will not accept a mix of true and false fields
### Sorting
The _sort_ argument is a comma separated list of fields to sort the results by. For example `sort=name,-age` results in a _option.sort_ value of `{'name':1,'age':-1}`. If no sort is specified then _option.sort_ is null and the results are not sorted.

Expand Down
5 changes: 5 additions & 0 deletions test/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ describe("query-to-mongo(query) =>", function () {
assert.ok(results.options)
assert.deepEqual(results.options, {fields: {b:false}})
})
it("should create omit option", function () {
var results = q2m("omit=b")
assert.ok(results.options)
assert.deepEqual(results.options, {fields: {b:false}})
})
it("should create sort option", function () {
var results = q2m("sort=a,+b,-c")
assert.ok(results.options)
Expand Down

0 comments on commit 8ebb073

Please sign in to comment.