I have record like this :
{ "Date" : ISODate("2013-06-28T18:30:00Z"), "Details" : { "Amount1" : -200, "Amount2" : 2800, "Amount3" : -100 }, 'NID' : 'T123RT', 'PID' : 'P123RT', "SettAmount" : 2500, "SettStatus" : "completed", "Status" : "completed", "StoreID" : "51ea54279d867b040b000008", "_id" : ObjectId("51ea54279d867b040b000013") }
I am trying to update the document like :
db.settlements.update({ 'StoreID' : "51ea54279d867b040b000008", 'Date' : ISODate("2013-06-28T18:30:00Z") }, { $unset : { 'NID' : "", 'PID' : "" } }, { $set : { 'SettStatus' : 'start', 'Status' : 'pending' } });
But, only unset operation is successful. what is the error in above query........?
Description. In MongoDB, the $unset operator is used to delete a particular field. The value specified in the $unset expression does not make any impact on the operation. The $unset has no effect when the field does not exist in the document.
$set outputs documents that contain all existing fields from the input documents and newly added fields. The $set stage is an alias for $addFields . Both stages are equivalent to a $project stage that explicitly specifies all existing fields in the input documents and adds the new fields.
To delete multiple documents, use db. collection. deleteMany() .
you have too many braces, here's correct command:
db.settlements.update( { 'StoreID': "51ea54279d867b040b000008", 'Date': ISODate("2013-06-28T18:30:00Z") }, { $unset: { 'NID' : "", 'PID' : "" }, $set: { 'SettStatus': 'start', 'Status': 'pending' } } );
in your command, you're using $set as <options>
in update command, not as part of <update>
http://docs.mongodb.org/manual/core/update/#crud-update-update
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With