Docs Menu

cursor.showRecordId()

項目一覧

cursor.showRecordId()

重要

mongosh メソッド

このページでは、mongosh メソッドについて記載しています。これは Node.js などの言語固有のドライバーのドキュメントではありません

MongoDB API ドライバーについては、各言語の MongoDB ドライバー ドキュメントを参照してください。

Appends the $recordId field to documents returned by a query. $recordId is the internal key that uniquely identifies a document in a collection. $recordId format:

'$recordId': Long(<int>)
次の値を返します。A modified cursor object that contains the document fields and the appended $recordId field.

このメソッドは、次の環境でホストされている配置で使用できます。

  • MongoDB Atlas はクラウドでの MongoDB 配置のためのフルマネージド サービスです

注意

このコマンドは、すべての MongoDB Atlas クラスターでサポートされています。すべてのコマンドに対する Atlas のサポートについては、「サポートされていないコマンド」を参照してください。

  • 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")
}
]

項目一覧