[SERVER-60414] Updating the immutable _id field should return the same error for all collection types Created: 03/Oct/21  Updated: 27/Oct/23  Resolved: 13/Oct/21

Status: Closed
Project: Core Server
Component/s: Shell
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Minor - P4
Reporter: Dmitry Agranat Assignee: Gregory Noma
Resolution: Gone away Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
Sprint: Execution Team 2021-10-18
Participants:

 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.



 Comments   
Comment by Louis Williams [ 04/Oct/21 ]

Time-series collections do not have a user-visible _id index and do not enforce _id uniqueness. The error should say instead "updates are not supported on time-series collections." dmitry.agranat would that clear up any confusion here?

CC michael.gargiulo

Generated at Thu Feb 08 05:49:45 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.