-
Type: Bug
-
Resolution: Done
-
Priority: Major - P3
-
Affects Version/s: None
-
Labels:None
While investigating SERVER-67539, we noticed that the documentation for showRecordId() has a stale example. There is more context in SERVER-67539 but I will explain the problem here as well. This pertains to the following docs page: https://www.mongodb.com/docs/manual/reference/method/cursor.showRecordId/.
At the bottom of the page, we have the following example:
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)
}
This used to be accurate, but the behavior changed in MongoDB 4.4 as part of PM-684. The server will now omit the "$recordId" field for this query:
MongoDB Enterprise > db.c.find({}, {$recordId: 1}).showRecordId() { "_id" : ObjectId("62fead4bee4c4666b602252e") } { "_id" : ObjectId("62fead4bee4c4666b6022530") } { "_id" : ObjectId("62fead4cee4c4666b6022532") }
We should either correct the example or delete it. The following query can be used instead against 4.4+ versions of the server to return results containing just the _id and $recordId fields:
MongoDB Enterprise > db.c.find({}, {_id: 1}).showRecordId() { "_id" : ObjectId("62fead4bee4c4666b602252e"), "$recordId" : NumberLong(1) } { "_id" : ObjectId("62fead4bee4c4666b6022530"), "$recordId" : NumberLong(2) } { "_id" : ObjectId("62fead4cee4c4666b6022532"), "$recordId" : NumberLong(3) }
- is related to
-
SERVER-67539 Discrepancy in `showRecordId()` behavior
- Closed