[JAVA-1055] Bad $set update of nested fields fails but throws no error Created: 02/Dec/13  Updated: 02/Dec/13  Resolved: 02/Dec/13

Status: Closed
Project: Java Driver
Component/s: Error Handling
Affects Version/s: 2.11.3
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Zohar Bar-Yehuda Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Windows and Linux, used through MATLAB



 Description   

Trying to update a nested field of an object that already exists as a value type, will result in an error when executed from the mongo shell:

> doc =

{t1:null} { "t1" : null }

> db.test.insert(doc)
> db.test.find()

{ "_id" : ObjectId("529c58a9642f618ff689a5eb"), "t1" : null }

> db.test.update(

{ "_id" : ObjectId("529c58a9642f618ff689a5eb")}

,{"$set":{"t1.t2":1}})
LEFT_SUBFIELD only supports Object: t1 not: 10

Trying the same with the JAVA driver (which I access from MATLAB, but I suppose native JAVA would be similar):
>> doc(1) = BasicDBObject('t1','');
>> db.getCollection('test').insert(doc)
>> db.getCollection('test').update(BasicDBObject('_id',doc(1).get('_id')),BasicDBObject('$set',BasicDBObject('t1.t2',1)))

This fails but returns no error (also other valid fields in doc won't be updated)



 Comments   
Comment by Jeffrey Yemin [ 02/Dec/13 ]

No problem. It is confusing...

Comment by Zohar Bar-Yehuda [ 02/Dec/13 ]

Yes, it works as expected now. Was using:
muri = MongoURI(connection_string)
db = muri.connectDB()

Changed to MongoClient and now it does return the errors.
Thanks for the help and sorry for the hassle...

Comment by Jeffrey Yemin [ 02/Dec/13 ]

Yes, if you use MongoClient instead of Mongo, it will by default report all errors. Are you saying that it's not doing that?

Comment by Zohar Bar-Yehuda [ 02/Dec/13 ]

You're correct, it's a write concern issue. The above doesn't return an error neither (returns N/A in the WriteResult)
Using this instead:
db.getCollection('test').insert(doc(1),WriteConcern(1))
does return an error.

This is what I get:
m = MongoClient()

m =

Mongo{authority=MongoAuthority{type=Direct, serverAddresses=[/127.0.0.1:27017], credentials={credentials={}}}, options=MongoOptions{description='null', connectionsPerHost=100, threadsAllowedToBlockForConnectionMultiplier=5, maxWaitTime=120000, connectTimeout=10000, socketTimeout=0, socketKeepAlive=false, autoConnectRetry=false, maxAutoConnectRetryTime=0, slaveOk=false, readPreference=primary, dbDecoderFactory=DefaultDBDecoder.DefaultFactory, dbEncoderFactory=DefaultDBEncoder.DefaultFactory, safe=false, w=0, wtimeout=0, fsync=false, j=false, socketFactory=javax.net.DefaultSocketFactory@7b58ef06, cursorFinalizerEnabled=true, writeConcern=WriteConcern

{ "getlasterror" : 1}

/ (Continue Inserting on Errors? false), alwaysUseMBeans=false}}

And also for my object:
db.getWriteConcern

ans =

WriteConcern

{ "getlasterror" : 1}

/ (Continue Inserting on Errors? false)

Doesn't this mean it should return the error unless instructed otherwise?

Comment by Jeffrey Yemin [ 02/Dec/13 ]

It's possible that MATLAB is using the default write concern from an old version of the Java driver, which is to not check for errors on updates.

To check this theory, are you able to get an error reported for any write error? For example, what happens if you insert the same document twice:

>> doc(1) = BasicDBObject('_id',1);
>> db.getCollection('test').insert(doc)
>> db.getCollection('test').insert(doc)

Can you show how the instance of Mongo is created? Can you try doing it like this:

m = new MongoClient();

This will use the correct default write concern, which is WriteConcern.ACKNOWLEDGED.

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