MongoDB findOne() method returns only one document that satisfies the criteria entered. If the criteria entered matches for more than one document, the method returns only one document according to natural ordering, which reflects the order in which the documents are stored in the database.
MongoDB findOne()方法仅返回一个满足输入条件的文档。 如果输入的条件匹配多个文档,则该方法将根据自然顺序仅返回一个文档,这反映了文档在数据库中的存储顺序。
MongoDB findOne (MongoDB findOne)
MongoDB findOne() syntax is:
MongoDB findOne()语法为:
db.collection.findOne(<criteria>, <projection>)
db.collection.findOne(<criteria>, <projection>)
criteria – specifies the selection criteria entered.
标准 –指定输入的选择标准。
projection – specifies the list of fields to be displayed in the returned document.
投影 –指定要在返回的文档中显示的字段列表。
Few important points about MongoDB findOne:
关于MongoDB findOne的几点要点:
- The projection parameter accepts the boolean values of 1 or true , 0 or false. If the projection fields are not specified, all the fields will be retrieved. projection参数接受布尔值1或true,0或false。 如果未指定投影字段,则将检索所有字段。
- MongoDB findOne() always includes the _id field even if not specified explicitly in the projection parameter unless it is excluded. MongoDB findOne()始终包含_id字段,即使未在projection参数中明确指定,除非将其排除。
- MongoDB findOne() returns only a document but not a cursor. MongoDB findOne()仅返回文档,而不返回游标。