Skip to content

Instantly share code, notes, and snippets.

@kjirou
Last active August 29, 2015 13:58
Show Gist options
  • Save kjirou/9968231 to your computer and use it in GitHub Desktop.
Save kjirou/9968231 to your computer and use it in GitHub Desktop.
mongoose のクエリ例
// Ref) http://mongoosejs.com/docs/queries.html
Person
.find({ occupation: /host/ })
.where('name.last').equals('Ghost')
.where('age').gt(17).lt(66)
.where('likes').in(['vaporizing', 'talking'])
.limit(10)
//.skip(1) // これもある
.sort('-occupation')
.select('name occupation') // fields オプションと同じ、{name:1, occupation:1} と同じ意味
.exec(callback); // find にコールバックを入れるとこれを実行したのと同じになる、入れないとクエリオブジェクトのまま
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment