[SERVER-22490] Casted type-change updates are discarded Created: 05/Feb/16  Updated: 05/Feb/16  Resolved: 05/Feb/16

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

Type: Bug Priority: Major - P3
Reporter: Nathaniel Kofalt 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-16801 update considers a change in numerica... Closed
Operating System: ALL
Steps To Reproduce:

A simple example:

// insert a document into a new table; number is interpreted as a double
db.example.insert({"foo": 1})
//--> WriteResult({ "nInserted" : 1 })
 
// good so far
db.example.find()
//--> { "_id" : ObjectId("56b4c6dcbfa50a533004158a"), "foo" : 1 }
 
// confirm the field is of type double
// ref: https://docs.mongodb.org/manual/reference/operator/query/type
db.example.count({"foo": {"$type": 1}})
//--> 1
 
// attempt to update field from double to integer; fails
db.example.update({"foo": {"$type": 1}}, {"$set": {"foo": NumberInt(1) }})
//--> WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 0 })
 
// doc still has a double
db.example.count({"foo": {"$type": 1}})
//--> 1
 
// update field from double to integer of a different value; succeeds
db.example.update({"foo": {"$type": 1}}, {"$set": {"foo": NumberInt(2) }})
// WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
 
// doc no longer has a double
db.example.count({"foo": {"$type": 1}})
//--> 0
 
// confirm doc now has an int
db.example.count({"foo": {"$type": 16}})
//--> 1

Participants:

 Description   

When attempting to update a document by changing the type of a field, that update appears to be discarded if the result is casted-equivalent. So far, I've observed this behavior when attempting to replace a double with an int of the same value.

Combined with SERVER-22489, this became an irritating problem; the only workaround I have so far is to update with some erroneous value, then update a second time to fix it.



 Comments   
Comment by Charlie Swanson [ 05/Feb/16 ]

Hi NathanielKofalt,

Thanks for the report. I think this is a duplicate of SERVER-16801, and I'm closing as such. Feel free to watch that ticket for updates.

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