[SERVER-2206] Updating _id field fails with $set, works on replacement Created: 10/Dec/10  Updated: 12/Jul/16  Resolved: 12/Dec/10

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

Type: Bug Priority: Major - P3
Reporter: Scott Hernandez (Inactive) Assignee: Eliot Horowitz (Inactive)
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Minor Change
Operating System: ALL
Participants:

 Description   

At the moment you can do an update to change the whole document, but not $set the _id.

This seems inconsistent; you should either be allowed to change the _id field, or not.

The current replacement model seems to just be a shortcut for delete/insert.



 Comments   
Comment by Eliot Horowitz (Inactive) [ 12/Dec/10 ]

Its immutable because semantically its the primary key, and is used as such in the code, and in various tools.

The code on the server was just there to make replication not break in that case, not to explicitly offer an atomic delete + insert.

I've never seen anyone rely on this.

Comment by Scott Hernandez (Inactive) [ 12/Dec/10 ]

I have a feeling people are relying on that functionality; someone specifically wrote that code on the server to support a quick, and atomic, delete+insert when changing the _id field on update.

I understand the _id field is currently immutable, but why is that? It seems like removing that restriction will keep existing code working and support more options; what is the downside? Is it an issue with the fact that it is actually a delete+insert and that is not obvious/expected?

Comment by auto [ 12/Dec/10 ]

Author:

{u'login': u'erh', u'name': u'Eliot Horowitz', u'email': u'eliot@10gen.com'}

Message: can never change _id with a full object update SERVER-2206
https://github.com/mongodb/mongo/commit/47d2007d88f9f8f93bb7c8af269246e94e22f76d

Comment by Eliot Horowitz (Inactive) [ 12/Dec/10 ]

It now throws an error as changing _id should never be allowed.

Comment by Barry Kaplan [ 10/Dec/10 ]

My preference would be ignore the _id in the update-document. Update all the values (except _id) of the existing-document with the values of the update-document.

Generated at Thu Feb 08 02:59:16 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.