Details
-
Task
-
Resolution: Duplicate
-
Major - P3
-
None
-
2.11.4
Description
I am trying to do an $inc operator from within the $set operation.
When I try this using the shell, it works perfectly fine:
db.S_M_users.update(
{ "sni" : 4 , "ki" : 0 , "ts" : 1184437800000, "snun" : "Amazon"},
{ $set:
, $inc : { "oc" : 1}},true,false)
But when I try to form the same query through java driver using update method it gets created like :
query:
updateCriteria:
{ "$set" : { "ki" : 0 , "sni" : 4 , "ts" : 1184437800000 , "snu" : "UCWyLWwoPCLHHJp4NSXFV1Dw" , "snun" : "Lorem ipsum dolor" , "ucm" : false , "uiu" : false , "$inc" :
}}
DB db = client.getDB("S_M_users");
WriteResult wr = db.getCollection("S_M_users").update(query, updateCriteria, true, false, 1);
db.S_M_users.update(
{ "sni" : 4 , "ki" : 0 , "ts" : 1184437800000 , "snun" : "Lorem ipsum dolor"},
{ "$set" : { "ki" : 0 , "sni" : 4 , "ts" : 1184437800000 , "snu" : "UCWyLWwoPCLHHJp4NSXFV1Dw" , "snun" : "Lorem ipsum dolor" , "ucm" : false , "uiu" : false , "$inc" :
}},true,false)
And in java driver I get following exception:
Error while updating record: { "serverUsed" : "CTPLSRV028:27017" , "err" : "Modified field name may not start with $" , "code" : 15896 , "n" : 0 , "lastOp" :
, "connectionId" : 19680328 , "ok" : 1.0}
There should be a way to use $inc from within a set operation using Java Driver