[SERVER-241] Can't change field data type when using $set Created: 18/Aug/09  Updated: 10/Sep/09  Resolved: 26/Aug/09

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

Type: Bug Priority: Major - P3
Reporter: Ryan Nitz Assignee: Eliot Horowitz (Inactive)
Resolution: Cannot Reproduce Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: Text File ChangeDataType.java    
Participants:

 Description   

The following code fails to convert the data type from a boolean to a double (calling $set). If this feature is not supported by $set, perhaps the driver should check the data type and throw an illegal argument exception if the types do not match.

if (doc.containsField(SiteDocField.HAS_SYND_FEED.key)) {
final Object obj = doc.get(SiteDocField.HAS_SYND_FEED.key);
if (obj != null)

{ double value = convertToDouble(obj); pCol.update(new BasicDBObject(SiteDocField.ID.key, id), new BasicDBObject("$set", new BasicDBObject(SiteDocField.HAS_SYND_FEED.key, value)), false, false); }

else

{ doc.removeField(SiteDocField.HAS_SYND_FEED.key); pCol.save(doc); }

pDb.getDb().getLastError();
}

The code below successfully changes the data type (by calling save(doc)).

if (doc.containsField(SiteDocField.HAS_SYND_FEED.key)) {
final Object obj = doc.get(SiteDocField.HAS_SYND_FEED.key);
if (obj != null)

{ double value = convertToDouble(obj); // THIS IS THE CODE THAT WORKS doc.put(SiteDocField.HAS_SYND_FEED.key, value); pCol.save(doc); }

else

{ doc.removeField(SiteDocField.HAS_SYND_FEED.key); }

pCol.save(doc);
pDb.getDb().getLastError();
}



 Comments   
Comment by Eliot Horowitz (Inactive) [ 10/Sep/09 ]

closed b/c resolved more than 2 week ago

Comment by Eliot Horowitz (Inactive) [ 26/Aug/09 ]

java test that works changing bool to double with $set

http://github.com/mongodb/mongo-java-driver/commit/6785d32efefa70d9bfcda5f17ac37a3ad966c3b5

Comment by Ryan Nitz [ 26/Aug/09 ]

I truncated this and removed any identifiable product info.

This uses a couple of custom objects and won't compile on its own.

In this example... both fields were boolean (trying to convert to double). It includes the code that works and the code that did not (using $set).

Let me know if you have any questions.

Comment by Eliot Horowitz (Inactive) [ 26/Aug/09 ]

in shell - but it shouldn't be different.
if you could send a java full program that reproduces - can work off of that

Comment by Ryan Nitz [ 26/Aug/09 ]

You can't reproduce in the Java driver or from the shell?

Comment by Eliot Horowitz (Inactive) [ 26/Aug/09 ]

take a look at jstests/set2.js

that seems like the same thing, but works fine.

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