Google News
logo
MongoDB - Interview Questions
State the difference between find() and limit() method.
find() : displays only selected data rather than all the data of a document. For example, if your document has 4 fields but you want to show only one, set the required field as 1 and others as 0.
 
db.COLLECTION_NAME.find({},);

limit() : limit function limits the number of records fetched. For example, if you have 7 documents but want to display only the first 4 documents in a collection, use limit. Syntax :
 
db.COLLECTION_NAME.find().limit(NUMBER);
Advertisement