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

cursor.showRecordId()

在此页面上

  • 定义
  • 例子
cursor.showRecordId()

重要

mongosh 方法

这是一个 mongosh方法。 这不是Node.js或其他特定于编程语言的驱动程序方法的文档。

在大多数情况下, mongosh方法的工作方式与传统 mongo shell 方法相同。但是,某些旧方法在mongosh中不可用。

有关旧版mongo shell 文档,请参阅相应 MongoDB Server 版本的文档:

对于 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

来年

cursor.size

在此页面上