cursor.showRecordId()

On this page本页内容

cursor.showRecordId()

mongo Shell Method

This page documents the mongo shell method, and does not refer to the MongoDB Node.js driver (or any other driver) method. 本页记录了mongo shell方法,未提及MongoDB Node.js驱动程序(或任何其他驱动程序)方法。For corresponding MongoDB driver API, refer to your specific MongoDB driver documentation instead.有关相应的MongoDB驱动程序API,请参阅特定的MongoDB驱动程序文档。

Changed in version 3.2.在版本3.2中更改。This method replaces the previous cursor.showDiskLoc().此方法将替换以前的cursor.showDiskLoc()

Modifies the output of a query by adding a field $recordId to matching documents. 通过向匹配文档添加字段$recordId来修改查询的输出。$recordId is the internal key which uniquely identifies a document in a collection. $recordId是唯一标识集合中文档的内部密钥。It has the form:其形式如下:

"$recordId": NumberLong(<int>)
Returns:A modified cursor object that contains documents with appended information describing the internal record key.一个修改过的游标对象,包含带有描述内部记录键的附加信息的文档。

Example示例

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:以下操作将showRecordId()方法附加到db.collection.find()方法,以便在匹配的文档中包含存储引擎记录信息:

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

The operation returns the following documents, which include the $recordId field:该操作返回以下文档,其中包括$recordId字段:

{
  "_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:您可以投影添加的字段$recordId,如下例所示:

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

This query returns only the _id field and the $recordId field in the matching documents:此查询仅返回匹配文档中的_id字段和$recordId字段:

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