cursor.showRecordId()

On this page本页内容

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.在版本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)
}
←  cursor.returnKey()cursor.size() →