Docs 菜单
Docs 主页
/
MongoDB Manual
/ / /

cursor.showRecordId()

在此页面上

  • 定义
  • 例子
cursor.showRecordId()

重要

mongosh 方法

本页面提供 mongosh 方法的相关信息。这不是特定于语言的驱动程序(例如 Node.js)的文档。

如需了解 MongoDB API 驱动程序,请参阅特定语言的 MongoDB 驱动程序文档。

$recordId字段附加到查询返回的文档。 $recordId是唯一标识集合中文档的内部密钥。 $recordId格式:

'$recordId': Long(<int>)
返回:修改后的游标对象,包含文档字段和附加的$recordId字段。

该示例使用此pizzas集合:

db.pizzas.insertMany( [
{ type: "pepperoni", size: "small", price: 4 },
{ type: "cheese", size: "medium", price: 7 },
{ type: "vegan", size: "large", price: 8 }
] )

以下 find()示例使用showRecordId()$recordId附加到输出中的pizza文档字段:

db.pizzas.find().showRecordId()

示例输出:

[
{
_id: ObjectId("62ffc70660b33b68e8f30435"),
type: 'pepperoni',
size: 'small',
price: 4,
'$recordId': Long("1")
},
{
_id: ObjectId("62ffc70660b33b68e8f30436"),
type: 'cheese',
size: 'medium',
price: 7,
'$recordId': Long("2")
},
{
_id: ObjectId("62ffc70660b33b68e8f30437"),
type: 'vegan',
size: 'large',
price: 8,
'$recordId': Long("3")
}
]

后退

cursor.returnKey

在此页面上