[SERVER-514] Setting _id in upsert() operation that uses $set Created: 02/Jan/10  Updated: 02/Jan/10  Resolved: 02/Jan/10

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

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

no matter


Participants:

 Description   

I want to add object with CERTAIN _id if object doesn't exist. Else, I want to use $set on it's properties.
What should I do?

> db.chatsessions.update(

{"_id": "test"}

,

{"_id":"test"}

,

{upsert: true}

);
> db.chatsessions.find();

{ "_id" : "test" }

<_id": "test1"},{"_id":"test1","$set":{"key": "value"}},

{upsert: true}

);
Modifiers and non-modifiers cannot be mixed
> db.chatsessions.update(

{"_id": "test1"}

,{"$set":{"_id": "test1", "key": "value"}},

{upsert: true}

);
Mod on _id not allowed
>

I think that the error "Modifiers and non-modifiers cannot be mixed" shouldn't occur in case of _id.
In case that an object exists already, _id should be ignored.



 Comments   
Comment by Eliot Horowitz (Inactive) [ 02/Jan/10 ]

_id on the right is redundant. On upsert query and mod are automatically combined

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