Model.findOne()

Parameters
Returns:
  • «Query»

Finds one document.

The conditions are cast to their respective SchemaTypes before the command is sent.

Note: conditions is optional, and if conditions is null or undefined, mongoose will send an empty findOne command to MongoDB, which will return an arbitrary document. If you’re querying by _id, use findById() instead.

Example:

  1. // Find one adventure whose `country` is 'Croatia', otherwise `null`
  2. await Adventure.findOne({ country: 'Croatia' }).exec();
  3. // using callback
  4. Adventure.findOne({ country: 'Croatia' }, function (err, adventure) {});
  5. // select only the adventures name and length
  6. await Adventure.findOne({ country: 'Croatia' }, 'name length').exec();