[JAVA-1149] $inc operator not supported with $set operation in update Created: 19/Mar/14  Updated: 11/Sep/19  Resolved: 19/Mar/14

Status: Closed
Project: Java Driver
Component/s: Write Operations
Affects Version/s: 2.11.4
Fix Version/s: None

Type: Task Priority: Major - P3
Reporter: Divya Jain Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: driver
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate

 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:

{"ki" : 0 , "sni" : 4 , "ts" : 1184437800000, "snu" : "UCWyLWwoPCLHHJp4NSXFV1Dw" , "snun" : "Amazon" , "ucm" : false , "uiu" : false}

, $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:

{ "sni" : 4 , "ki" : 0 , "ts" : 1184437800000 , "snun" : "Lorem ipsum dolor"}

updateCriteria:
{ "$set" : { "ki" : 0 , "sni" : 4 , "ts" : 1184437800000 , "snu" : "UCWyLWwoPCLHHJp4NSXFV1Dw" , "snun" : "Lorem ipsum dolor" , "ucm" : false , "uiu" : false , "$inc" :

{ "oc" : 1}

}}

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" :

{ "oc" : 1}

}},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" :

{ "$ts" : 1395147947 , "$inc" : 1}

, "connectionId" : 19680328 , "ok" : 1.0}

There should be a way to use $inc from within a set operation using Java Driver



 Comments   
Comment by Gianfranco Palumbo [ 19/Mar/14 ]

Closing this a duplicate

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