发布于 2015-09-14 14:44:09 | 191 次阅读 | 评论: 0 | 来源: 网络整理

db.collection.findOne(query, projection)
参数:
  • 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 projection argument will resemble the following prototype:

    { field1: boolean, field2: boolean ... }
    

    The boolean can take the following include or exclude values:

    • 1 or true to include. The findOne() method always includes the _id field even if the field is not explicitly stated to return in the projection parameter.
    • 0 or false to exclude.

    The projection cannot contain both include and exclude specifications except for the exclusion of the _id field.

    Omit the projection parameter to return all the fields in the matching documents.

返回:

One document that satisfies the query specified as the argument to this method. If the projection argument is specified, the returned document contains only the projection fields, and the _id field if you do not explicitly exclude the _id field.

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.

最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务