How to use $unset and $set in combination in mongoDB

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

Leave a Comment