Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save nguyenphuongduy124/70a4c56f8b0411453cb2e340ea975267 to your computer and use it in GitHub Desktop.
Save nguyenphuongduy124/70a4c56f8b0411453cb2e340ea975267 to your computer and use it in GitHub Desktop.
MongoDB and Mongoose - Nối các truy vấn để thu hẹp kết quả tìm kiếm
If you don’t pass the callback as the last argument to Model.find() (or to the other search methods), the query is not executed. You can store the query in a variable for later use. This kind of object enables you to build up a query using chaining syntax. The actual db search is executed when you finally chain the method .exec(). You always need to pass your callback to this last method. There are many query helpers, here we’ll use the most ‘famous’ ones.
Find people who like burrito. Sort them by name, limit the results to two documents, and hide their age. Chain .find(), .sort(), .limit(), .select(), and then .exec(). Pass the done(err, data) callback to exec().
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment