top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

MongoDB: Difference between find and findOne methods in mongoDB ?

+2 votes
1,350 views
MongoDB: Difference between find and findOne methods in mongoDB ?
posted Jun 28, 2015 by Vikram Singh

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

+1 vote

The basic difference between find() and findOne() is find() method can return multiple documents in search result while findOne() returns only the first document which matches selection criteria.

answer Jun 28, 2015 by Alok
0 votes

findOne():Returns one document that satisfies the specified query criteria. If multiple documents satisfy the query, this method returns the first document according to the natural order which reflects the order of documents on the disk.
syntax:

$query=array('name_filed'=>$name_any); // in php
    >db.collection.findOne($query);   //mongodb terminal

But In case of find(),
Returns all document which matches criteria or query;

 >db.collection_name.find($query);
answer Feb 7, 2016 by Shivam Kumar Pandey
...