cursor.showRecordId()

  • cursor.showRecordId()

mongo Shell Method

This page documents the mongo shell method, and doesnot refer to the MongoDB Node.js driver (or any other driver)method. For corresponding MongoDB driver API, refer to your specificMongoDB driver documentation instead.

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

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

  1. "$recordId": NumberLong(<int>)

Returns:A modified cursor object that contains documents withappended information describing the internal record key.

Example

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

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

The operation returns the following documents, which include the $recordIdfield:

  1. {
  2. "_id" : ObjectId("53908ccb18facd50a75bfbac"),
  3. "a" : 1,
  4. "b" : 1,
  5. "$recordId" : NumberLong(168112)
  6. }
  7. {
  8. "_id" : ObjectId("53908cd518facd50a75bfbad"),
  9. "a" : 1,
  10. "b" : 2,
  11. "$recordId" : NumberLong(168176)
  12. }

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

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

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

  1. {
  2. "_id" : ObjectId("53908ccb18facd50a75bfbac"),
  3. "$recordId" : NumberLong(168112)
  4. }
  5. {
  6. "_id" : ObjectId("53908cd518facd50a75bfbad"),
  7. "$recordId" : NumberLong(168176)
  8. }