The first parameter is the query.
The second parameter (which is optional) is the ie projection if you want to limit the content of the matched documents
collection.find( { qty: { $gt: 25 } }, { item: 1, qty: 1 },function(e,docs){})
would mean getting only the item and qty fields in consistent documents
The third parameter is a callback function that is called after the request completes. function(e, docs) is the mongodb driver for node.js. syntax The first parameter e is an error. docs is an array of consistent documents. If an error occurs, it is specified in e . If the request is successful, the consistent documents are given in the second parameter docs (the name can be whatever you want).
cursor has various methods that can be used to manage consistent documents before mongoDB returns them. collection.find ({qty: {$ gt: 25}}, {item: 1, qty: 1}) is a cursor on which you can perform various operations.
collection.find( { qty: { $gt: 25 } }, { item: 1, qty: 1 }).skip(10).limit(5).toArray(function(e,docs){ ... })
means that you skip the first 10 agreed documents and then return a maximum of 5 documents.
All these materials are given in the documents . I think itβs better to use mongoose instead of the native driver because of the features and popularity.
source share