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

    • Type: Icon: Improvement Improvement
    • Resolution: Gone away
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: Shell
    • None
    • Execution Team 2021-10-18

      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.

            Assignee:
            gregory.noma@mongodb.com Gregory Noma
            Reporter:
            dmitry.agranat@mongodb.com Dmitry Agranat
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: