Docs Menu

Docs HomeDevelop ApplicationsMongoDB Manual

cursor.showRecordId()

On this page

  • Example
cursor.showRecordId()

Important

mongosh Method

This is a mongosh method. This is not the documentation for Node.js or other programming language specific driver methods.

In most cases, mongosh methods work the same way as the legacy mongo shell methods. However, some legacy methods are unavailable in mongosh.

For the legacy mongo shell documentation, refer to the documentation for the corresponding MongoDB Server release:

For MongoDB API drivers, refer to the language specific MongoDB driver documentation.

Changed in version 3.2: This method replaces the previous cursor.showDiskLoc().

Modifies the output of a query by adding a field $recordId to matching documents. $recordId is the internal key which uniquely identifies a document in a collection. It has the form:

"$recordId": NumberLong(<int>)
Returns:A modified cursor object that contains documents with appended information describing the internal record key.

The following operation appends the showRecordId() method to the db.collection.find() method in order to include storage engine record information in the matching documents:

db.collection.find( { a: 1 } ).showRecordId()

The operation returns the following documents, which include the $recordId field:

{
"_id" : ObjectId("53908ccb18facd50a75bfbac"),
"a" : 1,
"b" : 1,
"$recordId" : NumberLong(168112)
}
{
"_id" : ObjectId("53908cd518facd50a75bfbad"),
"a" : 1,
"b" : 2,
"$recordId" : NumberLong(168176)
}

You can project the added field $recordId, as in the following example:

db.collection.find( { a: 1 }, { $recordId: 1 } ).showRecordId()

This query returns only the _id field and the $recordId field in the matching documents:

{
"_id" : ObjectId("53908ccb18facd50a75bfbac"),
"$recordId" : NumberLong(168112)
}
{
"_id" : ObjectId("53908cd518facd50a75bfbad"),
"$recordId" : NumberLong(168176)
}
←  cursor.returnKey()cursor.size() →

On this page