[SERVER-18075] Behavior of Mongo update is different in 2.4 vs 2.6 Created: 15/Apr/15  Updated: 15/Apr/15  Resolved: 15/Apr/15

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

Type: Bug Priority: Critical - P2
Reporter: Rajesh Sharma Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-5289 _id field not taken from query during... Closed
Operating System: ALL
Steps To Reproduce:

run following in 2.4 vs 2.6 and see the difference. This is creating issue in our code due to upgrade.

db.books.update(
{_id:1234},
{
item: "XYZ123",
stock: 10,
info:

{ publisher: "2255", pages: 150 }

,
tags: [ "baking", "cooking" ]
},

{ upsert: true, multi: false}

)

In 2.4 if the document is missing then it is creating the following document.
---------------------------------------
{
"_id" : ObjectId("552eb41bb0af794da9287199"),
"item" : "XYZ123",
"stock" : 10.0,
"info" :

{ "publisher" : "2255", "pages" : 150.0 }

,
"tags" : ["baking", "cooking"]
}

In 2.6 it is creating the following in same condition
----------------------------------------------------------------
{
"_id" : 1234.0,
"item" : "XYZ123",
"stock" : 10.0,
"info" :

{ "publisher" : "2255", "pages" : 150.0 }

,
"tags" : ["baking", "cooking"]
}

Participants:

 Description   

Behavior of Mongo update is different in 2.4 vs 2.6.

In our case _id was null so in 2.4 it was creating multiple document and which was correct behavior. in 2.6 the behavior changed and the Id is becoming null which is creating nullpointer exception and later all upsert are only updating that document instead of inserting.

Steps to Reproduce
------------------------------------
try to run following in 2.4 vs 2.6 and see the difference. This is creating issue in our code due to upgrade.

db.books.update(
{_id:1234},
{
item: "XYZ123",
stock: 10,
info:

{ publisher: "2255", pages: 150 }

,
tags: [ "baking", "cooking" ]
},

{ upsert: true, multi: false}

)

In 2.4 if the document is missing then it is creating the following document.
---------------------------------------
{
"_id" : ObjectId("552eb41bb0af794da9287199"),
"item" : "XYZ123",
"stock" : 10.0,
"info" :

{ "publisher" : "2255", "pages" : 150.0 }

,
"tags" : ["baking", "cooking"]
}

In 2.6 it is creating the following in same condition
----------------------------------------------------------------
{
"_id" : 1234.0,
"item" : "XYZ123",
"stock" : 10.0,
"info" :

{ "publisher" : "2255", "pages" : 150.0 }

,
"tags" : ["baking", "cooking"]
}



 Comments   
Comment by J Rassi [ 15/Apr/15 ]

Hi,

The 2.4 behavior has been classified as a bug that was fixed for the 2.6.0 production release in SERVER-5289.

There's no way to precisely emulate the previous behavior in current versions of the server, unfortunately. However, this will be possible once SERVER-18076 is resolved.

I'm closing this ticket as a duplicate of SERVER-5289.

~ Jason Rassi

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