|
We can insert documents with $recordId as a field. However, on querying with showRecordId:true, the field is overwritten by the true recordId instead of being displayed. When showRecordId:false, we see the $recordId field that we set.
MongoDB Enterprise rs:PRIMARY> db.newcoll.insert({$recordId: 12, a: 1})
|
WriteResult({ "nInserted" : 1 })
|
MongoDB Enterprise rs:PRIMARY> db.newcoll.find()
|
{ "_id" : ObjectId("65c27f064bb7df438ffb4d1c"), "$recordId" : 12, "a" : 1 }
|
MongoDB Enterprise rs:PRIMARY> db.newcoll.find().showRecordId()
|
{ "_id" : ObjectId("65c27f064bb7df438ffb4d1c"), "$recordId" : NumberLong(1), "a" : 1 }
|
The document exists properly on disk. And it exists in properly in the oplog too:
MongoDB Enterprise rs:PRIMARY> use local
|
switched to db local
|
MongoDB Enterprise rs:PRIMARY> db.oplog.rs.find({ns: /newcoll/}).pretty()
|
{
|
"op" : "i",
|
"ns" : "test.newcoll",
|
"ui" : UUID("4c079773-1ac9-44e9-9ee5-5d2b5f85ce7b"),
|
"o" : {
|
"_id" : ObjectId("65c27f064bb7df438ffb4d1c"),
|
"$recordId" : 12,
|
"a" : 1
|
},
|
"o2" : {
|
"_id" : ObjectId("65c27f064bb7df438ffb4d1c")
|
},
|
"ts" : Timestamp(1707245318, 2),
|
"t" : NumberLong(1),
|
"v" : NumberLong(2),
|
"wall" : ISODate("2024-02-06T18:48:38.177Z")
|
}
|
So it seems like in the query layer, the field is being swapped out with the recordId when showRecordId:true.
|