Hướng dẫn findone mongodb
Docs Home → MongoDB Manual db.collection.findOne(query, projection, options)
Importantmongosh MethodThis page documents a For MongoDB API drivers, refer to the language-specific MongoDB driver documentation. For the legacy
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.
Starting in MongoDB 4.2, if the client that issued ImportantLanguage ConsistencyThe
For fields in an embedded documents, you can specify the field using either:
The A
For more information on projection, see also:
The following operation returns a single document from the bios collection: The following operation returns the first matching document from the bios collection where either the field
The The following operation finds a document in the
bios collection and returns only the
The following operation returns a document in the bios collection where the
You cannot apply cursor methods to the result of
You can specify query options to modify query behavior and indicate how results are returned. For example, to define variables that you can access elsewhere in the Create a collection
The following example defines a
Output: To see all available query options, see FindOptions. |