Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-67539

Discrepancy in `showRecordId()` behavior

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Works as Designed
    • Icon: Major - P3 Major - P3
    • None
    • None
    • None
    • None
    • ALL
    • QE 2022-07-25, QE 2022-08-08, QE 2022-08-22

    Description

      While working on SERVER-67326 we noticed a weird behavior of `showRecordId()` and not sure it is working at expected.

      `showRecordId()` is a shell method which "modifies the output of a query by adding a field $recordId to matching documents". 

      While running the following queries, I assumed that all of them should have `$recordId` in their output. However, this is only the case for the first one.

      jsTestLog(coll.find({}).showRecordId().toArray());
      jsTestLog(coll.find({}, {$recordId: 1}).toArray());
      jsTestLog(coll.find({}, {$recordId: 1}).showRecordId().toArray());

       

      Here is the output:
       

      ,----
      | [
      | 	{
      | 		"_id" : ObjectId("62b619e0d3af55ae13afb1cf"),
      | 		"a" : 1,
      | 		"b" : 1,
      | 		"$recordId" : NumberLong(1)
      | 	},
      | 	{
      | 		"_id" : ObjectId("62b619e0d3af55ae13afb1d0"),
      | 		"a" : 1,
      | 		"b" : 2,
      | 		"$recordId" : NumberLong(2)
      | 	},
      | 	{
      | 		"_id" : ObjectId("62b619e0d3af55ae13afb1d1"),
      | 		"a" : 2,
      | 		"b" : 2,
      | 		"$recordId" : NumberLong(3)
      | 	},
      | 	{
      | 		"_id" : ObjectId("62b619e0d3af55ae13afb1d2"),
      | 		"a" : 2,
      | 		"b" : 3,
      | 		"$recordId" : NumberLong(4)
      | 	}
      | ]
      `----
      ,----
      | [
      | 	{
      | 		"_id" : ObjectId("62b619e0d3af55ae13afb1cf")
      | 	},
      | 	{
      | 		"_id" : ObjectId("62b619e0d3af55ae13afb1d0")
      | 	},
      | 	{
      | 		"_id" : ObjectId("62b619e0d3af55ae13afb1d1")
      | 	},
      | 	{
      | 		"_id" : ObjectId("62b619e0d3af55ae13afb1d2")
      | 	}
      | ]
      `----
      ,----
      | [
      | 	{
      | 		"_id" : ObjectId("62b619e0d3af55ae13afb1cf")
      | 	},
      | 	{
      | 		"_id" : ObjectId("62b619e0d3af55ae13afb1d0")
      | 	},
      | 	{
      | 		"_id" : ObjectId("62b619e0d3af55ae13afb1d1")
      | 	},
      | 	{
      | 		"_id" : ObjectId("62b619e0d3af55ae13afb1d2")
      | 	}
      | ]
      `----

       

      showRecordId() documentation → https://www.mongodb.com/docs/v6.0/reference/method/cursor.showRecordId/

       

      PS: the issue also doesn’t seem to be SBE or classic engine specific.

      Attachments

        Activity

          People

            david.storch@mongodb.com David Storch
            denis.grebennicov@mongodb.com Denis Grebennicov
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: