Definition定义
cursor.showRecordId()-
Important
mongosh
Method方法This page documents a本页记录了一种mongoshmethod. This is not the documentation for a language-specific driver, such as Node.js.mongosh方法。这不是针对特定语言驱动程序(如Node.js)的文档。For MongoDB API drivers, refer to the language-specific MongoDB driver documentation.有关MongoDB API驱动程序,请参阅特定语言的MongoDB驱动程序文档。Appends the将$recordIdfield to documents returned by a query.$recordIdis the internal key that uniquely identifies a document in a collection.$recordIdformat:$recordId字段附加到查询返回的文档中。$recordId是唯一标识集合中文档的内部键。$recordId格式:'$recordId': Long(<int>)Returns:返回A modified cursor object that contains the document fields and the appended一个修改后的游标对象,包含文档字段和附加的$recordIdfield.$recordId字段。
Compatibility兼容性
This method is available in deployments hosted in the following environments:此方法在以下环境中托管的部署中可用:
- MongoDB Atlas
: The fully managed service for MongoDB deployments in the cloud:云中MongoDB部署的完全托管服务
Note
This command is supported in all MongoDB Atlas clusters. 所有MongoDB Atlas集群都支持此命令。For information on Atlas support for all commands, see Unsupported Commands.有关Atlas支持所有命令的信息,请参阅不支持的命令。
- MongoDB Enterprise
: The subscription-based, self-managed version of MongoDB:MongoDB的基于订阅的自我管理版本 - MongoDB Community
: The source-available, free-to-use, and self-managed version of MongoDB:MongoDB的源代码可用、免费使用和自我管理版本
Example示例
The example uses this 该示例使用此pizzas collection:pizzas集合:
db.pizzas.insertMany( [
{ type: "pepperoni", size: "small", price: 4 },
{ type: "cheese", size: "medium", price: 7 },
{ type: "vegan", size: "large", price: 8 }
] )
The following 以下find() example uses showRecordId() to append the $recordId to the pizza document fields in the output:find()示例使用showRecordId()将$recordId附加到输出中的pizza文档字段:
db.pizzas.find().showRecordId()
Example output:示例输出:
[
{
_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")
}
]