- Reference >
- JavaScript Methods >
- db.collection.findOne()
db.collection.findOne()¶
-
db.collection.findOne(query, projection)¶ Parameters: - query (document) – Optional. A document that specifies the query using the JSON-like syntax and query operators.
- projection (document) –
Optional. Controls the fields to return, or the projection. The
projectionargument will resemble the following prototype:The
booleancan take the following include or exclude values:1ortrueto include. ThefindOne()method always includes the _id field even if the field is not explicitly stated to return in the projection parameter.0orfalseto exclude.
The
projectioncannot contain both include and exclude specifications except for the exclusion of the_idfield.Omit the
projectionparameter to return all the fields in the matching documents.
Returns: One document that satisfies the query specified as the argument to this method. If the
projectionargument is specified, the returned document contains only theprojectionfields, and the_idfield if you do not explicitly exclude the_idfield.Returns only one document that satisfies the specified query. 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 disc. In capped collections, natural order is the same as insertion order.