[SERVER-20390] Updating just the type for a numeric field does not work Created: 14/Sep/15  Updated: 09/Dec/15  Resolved: 15/Sep/15

Status: Closed
Project: Core Server
Component/s: Write Ops
Affects Version/s: 3.0.3, 3.0.6
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Joakim Nordling Assignee: Sam Kleinman (Inactive)
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Seen on CentOS 7.1, both in 3.0.3 and 3.0.6. Not tested on anything else.


Issue Links:
Duplicate
duplicates SERVER-16801 update considers a change in numerica... Closed
Backwards Compatibility: Fully Compatible
Operating System: Linux
Steps To Reproduce:

1. Let's store the value 0 as double and verify it indeed is a double:

> db.test.update({"_id" : ObjectId("55f6c676e779893076f77e6b")}, { $set: {"test": 0} }, {upsert: true})
WriteResult({
	"nMatched" : 0,
	"nUpserted" : 1,
	"nModified" : 0,
	"_id" : ObjectId("55f6c676e779893076f77e6b")
})
> db.test.find( { test: { $type: 1 } } );
{ "_id" : ObjectId("55f6c676e779893076f77e6b"), "test" : 0 }
> db.test.find( { test: { $type: 16 } } );

2. Try to replace it with value 0 as a 32-bit integer and verify it's still a double:

> db.test.update({"_id" : ObjectId("55f6c676e779893076f77e6b")}, { $set: {"test": NumberInt(0)} }, {upsert: true})
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 0 })
> db.test.find( { test: { $type: 1 } } );
{ "_id" : ObjectId("55f6c676e779893076f77e6b"), "test" : 0 }
> db.test.find( { test: { $type: 16 } } );

3. Change the number to 1 and make sure it's a 32-bit integer after this:

> db.test.update({"_id" : ObjectId("55f6c676e779893076f77e6b")}, { $set: {"test": NumberInt(1)} }, {upsert: true})
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
> db.test.find( { test: { $type: 1 } } );
> db.test.find( { test: { $type: 16 } } );
{ "_id" : ObjectId("55f6c676e779893076f77e6b"), "test" : 1 }

4. Now let's change the value successfully to 0 as a 32-bit integer:

> db.test.update({"_id" : ObjectId("55f6c676e779893076f77e6b")}, { $set: {"test": NumberInt(0)} }, {upsert: true})
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
> db.test.find( { test: { $type: 1 } } );
> db.test.find( { test: { $type: 16 } } );
{ "_id" : ObjectId("55f6c676e779893076f77e6b"), "test" : 0 }

Participants:

 Description   

If you store the value 0 as a double in a field, you can't change the value 0 to a 32 bit integer without switching the value to something else in between.
It appears MongoDB on update considers 0 (the double) to be equal to the new value 0 (32-bit integer) and does not do any update.



 Comments   
Comment by Joakim Nordling [ 15/Sep/15 ]

Thanks Stephen,

I upvoted and am watching the SERVER-16801 now. Sorry I didn't notice I was creating a duplicate.

Regards,
Joakim

Comment by Stennie Steneker (Inactive) [ 15/Sep/15 ]

Hi Joakim,

Thanks for reporting. This is a duplicate of SERVER-16801; please watch/upvote that issue for updates.

Regards,
Stephen

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