collection.findOne
Returns one document that satisfies the specified query criteria on the collection or view. 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. In capped collections, natural order is the same as insertion order. If no document satisfies the query, the method returns null.
Arguments
query
(String|ObjectId|Object)[
options
] (Object|String|Array): If theoptions
is a string, it will be parsed as the projections to select.[
callback
] (function)
Returns
A promise.
Example
users.findOne({name: 'foo'}).then((doc) => {});
users.findOne({name: 'foo'}, 'name').then((doc) => {
// only the name projection will be selected
});
users.findOne({name: 'foo'}, { projection: { name: 1 } }); // equivalent
users.findOne({name: 'foo'}, '-name').then((doc) => {
// all the fields except the name projection will be selected
});
users.findOne({name: 'foo'}, { projection: {name: -1} }); // equivalent