Created
May 26, 2020 17:42
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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