Skip to content

Instantly share code, notes, and snippets.

@moaoa
Created July 16, 2020 10:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save moaoa/0a60ede30d0a045fb43e1d93dd1fe0ad to your computer and use it in GitHub Desktop.
Save moaoa/0a60ede30d0a045fb43e1d93dd1fe0ad to your computer and use it in GitHub Desktop.
// With a JSON doc
Person.
find({
occupation: /host/,
'name.last': 'Ghost',
age: { $gt: 17, $lt: 66 },
likes: { $in: ['vaporizing', 'talking'] } // see if the value of likes included in ['vaporizing, 'talking'] array
// syntax {property: {$in: array...}}
}).
limit(10).
sort({ occupation: -1 }).
select({ name: 1, occupation: 1 }).
exec(callback);
// Using query builder
Person.
find({ occupation: /host/ }).
where('name.last').equals('Ghost').
where('age').gt(17).lt(66).
where('likes').in(['vaporizing', 'talking']).
limit(10).
sort('-occupation').
select('name occupation').
exec(callback);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment