MongoDB findOne示例

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的几点要点:

  1. 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。 如果未指定投影字段,则将检索所有字段。
  2. MongoDB findOne() always includes the _id field even if not specified explicitly in the projection parameter unless it is excluded.

    MongoDB findOne()始终包含_id字段,即使未在projection参数中明确指定,除非将其排除。
  3. MongoDB findOne() returns only a document but not a cursor.

    MongoDB findOne()仅返回文档,而不返回游标。

MongoDB findOne –空查询规范 (

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值