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

Updating the immutable _id field should return the same error for all collection types

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Minor - P4
    • Resolution: Gone away
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Shell
    • Labels:
      None
    • Sprint:
      Execution Team 2021-10-18

      Description

      Following this example, I created a time series collection.

      When trying to update the immutable _id field, I am getting Namespace test.weather is a timeseries collection error:

      myReplicaSet5:PRIMARY> db.weather.updateOne({_id: ObjectId("61598144efba71465c1ab286")}, {$set: { _id: ObjectId("61597c28efba71465c1a9999")}})
      uncaught exception: WriteError({
      	"index" : 0,
      	"code" : 166,
      	"errmsg" : "Namespace test.weather is a timeseries collection",
      	"op" : {
      		"q" : {
      			"_id" : ObjectId("61598144efba71465c1ab286")
      		},
      		"u" : {
      			"$set" : {
      				"_id" : ObjectId("61597c28efba71465c1a9999")
      			}
      		},
      		"multi" : false,
      		"upsert" : false
      	}
      }) :
      WriteError({
      	"index" : 0,
      	"code" : 166,
      	"errmsg" : "Namespace test.weather is a timeseries collection",
      	"op" : {
      		"q" : {
      			"_id" : ObjectId("61598144efba71465c1ab286")
      		},
      		"u" : {
      			"$set" : {
      				"_id" : ObjectId("61597c28efba71465c1a9999")
      			}
      		},
      		"multi" : false,
      		"upsert" : false
      	}
      })
      

      The expected error should be the same as for any other collection type, for example, trying to update the _id field on a regular collection products:

      myReplicaSet5:PRIMARY> db.products.updateOne({_id: ObjectId("61598144efba71465c1ab286")}, {$set: { _id: ObjectId("61597c28efba71465c1a9999")}})
      WriteError({
      	"index" : 0,
      	"code" : 66,
      	"errmsg" : "Performing an update on the path '_id' would modify the immutable field '_id'",
      	"op" : {
      		"q" : {
      			"_id" : ObjectId("61598144efba71465c1ab286")
      		},
      		"u" : {
      			"$set" : {
      				"_id" : ObjectId("61597c28efba71465c1a9999")
      			}
      		},
      		"multi" : false,
      		"upsert" : false
      	}
      }) :
      WriteError({
      	"index" : 0,
      	"code" : 66,
      	"errmsg" : "Performing an update on the path '_id' would modify the immutable field '_id'",
      	"op" : {
      		"q" : {
      			"_id" : ObjectId("61598144efba71465c1ab286")
      		},
      		"u" : {
      			"$set" : {
      				"_id" : ObjectId("61597c28efba71465c1a9999")
      			}
      		},
      		"multi" : false,
      		"upsert" : false
      	}
      })
      

      There should be nothing special about the _id filed on a time series collection.

        Attachments

          Activity

            People

            Assignee:
            gregory.noma Gregory Noma
            Reporter:
            dmitry.agranat Dmitry Agranat
            Participants:
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: