Discuss Find Methods in MongoDB?

Finding and retrieving documents from the collection has two methods:

  • findOne(filter)
  • find(filter)

Both methods accept a filter optionally where the filter is used to filter the documents for finding or retrieving.

With findOne() we can get the first document of the collection. If we pass a filter for findOne(), we will get the first match of the documents.

db.collectionName.findOne({key:value})

With find() we can get all the documents from the collection. If we pass the filter to find() it will return with filtered documents

db.collectionName.find({key:value})