定義
cursor.showRecordId()重要
mongosh メソッド
This page documents a
mongoshmethod. This is not the documentation for a language-specific driver, such as Node.js.MongoDB API ドライバーについては、各言語の「MongoDB ドライバーのドキュメント」を参照してください。
クエリによって返されたドキュメントに
$recordIdフィールドを追加します。$recordIdは、コレクション内のドキュメントを一意に識別する内部キーです。$recordId形式:'$recordId': Long(<int>) 次の値を返します。 ドキュメント フィールドと追加の
$recordIdフィールドを含む変更済みカーソル オブジェクト。
互換性
このメソッドは、次の環境でホストされている配置で使用できます。
- MongoDB Atlas: The fully managed service for MongoDB deployments in the cloud
注意
This command is supported in all MongoDB Atlas clusters. For information on Atlas support for all commands, see Unsupported Commands.
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 } ] )
The following find() example uses showRecordId() to append the $recordId to the pizza document fields in the output:
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") } ]