[SERVER-10113] Reodering of update clause causes timestamp to not be auto-populated Created: 02/Jul/13  Updated: 06/Mar/14  Resolved: 08/Jul/13

Status: Closed
Project: Core Server
Component/s: Write Ops
Affects Version/s: 2.4.4
Fix Version/s: None

Type: Bug Priority: Minor - P4
Reporter: Clifford Hammerschmidt Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-10123 Support Timestamp(0,0) server replace... Closed
Operating System: ALL
Participants:

 Description   

db.col.update({_id:1},{$setOnInsert:{ts:new BsonTimestamp(0,0)}},

{upsert:true}

);

should auto-populate the timestamp like a regular insert would. (i.e. if the timestamp is the first or second entry in the $setOnInsert sub-document.)



 Comments   
Comment by Scott Hernandez (Inactive) [ 08/Jul/13 ]

Update, with $mods, does not support this behavior so I've added a feature request for this: SERVER-10123.

Comment by Sridhar Nanjundeswaran [ 05/Jul/13 ]

tanglebones - The above example should make it clear why I am moving it back to server. Looks you caught it as soon as I moved and before I posted my repro

Comment by Sridhar Nanjundeswaran [ 05/Jul/13 ]

During an update (or upsert), the server seems to be reordering the update clause which causes the timestamp to not be populated.

> db.tsauto.drop()
true
> db.tsauto.insert({_id:1, ts:new Timestamp(0,0), a:1})
> db.tsauto.find()
{ "_id" : 1, "ts" : { "t" : 1373057472, "i" : 1 }, "a" : 1 }
> db.tsauto.update({_id:1}, {$set:{ts:new Timestamp(0,0), a:11}})
> db.tsauto.find()
{ "_id" : 1, "ts" : { "t" : 0, "i" : 0 }, "a" : 11 }

Also as seen in the upsert below

> db.tsauto.drop()
true
> db.tsauto.update({_id:1},{$setOnInsert:{ts:new Timestamp(0,0)}}, {upsert:true}
)
> db.tsauto.update({_id:2},{$setOnInsert:{ts:new Timestamp(0,0), sts:1}}, {upser
t:true})
> db.tsauto.update({_id:3},{$setOnInsert:{ts:new Timestamp(0,0), uts:1}}, {upser
t:true})
> db.tsauto.find()
{ "_id" : 1, "ts" : { "t" : 1373057632, "i" : 1 } }
{ "_id" : 2, "sts" : 1, "ts" : { "t" : 0, "i" : 0 } }
{ "_id" : 3, "ts" : { "t" : 1373057667, "i" : 1 }, "uts" : 1 }

Comment by Clifford Hammerschmidt [ 05/Jul/13 ]

Sridhar, I take it by your moving it back to server you don't agree with it being an issue with the C# driver?

Comment by Daniel Pasette (Inactive) [ 02/Jul/13 ]

Moved this issue to the C# driver project.

Comment by Clifford Hammerschmidt [ 02/Jul/13 ]

I was using the c# driver (v1.8.1) ... might be an issue with it specifically?

collection.Update(Query.EQ("_id","test"),Update.SetOnInsert("ts", new BsonTimestamp(0,0)).AddToSet("state","req"), UpdateFlags.Upsert);

Comment by Daniel Pasette (Inactive) [ 02/Jul/13 ]

BsonTimestamp is not defined.

The following works as designed:

db.col.update({_id:1},{$setOnInsert:{ts:new Timestamp(0,0)}},{upsert:true});
> db.col.find()
{ "_id" : 1, "ts" : { "t" : 1372803371, "i" : 1 } }

Generated at Thu Feb 08 03:22:18 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.