定义
兼容性
此方法可用于以下环境中托管的部署:
- MongoDB Atlas :用于在云中部署MongoDB 的完全托管服务
MongoDB Enterprise:基于订阅、自我管理的 MongoDB 版本
MongoDB Community:源代码可用、免费使用且可自行管理的 MongoDB 版本
例子
该示例使用此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") } ]