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

后端 未结 1 1273
一向
一向 2020-12-09 02:15

I have record like this :

{
    \"Date\" : ISODate(\"2013-06-28T18:30:00Z\"),
    \"Details\" : {
            \"Amount1\" : -200,
            \"Amount2\" :          


        
相关标签:
1条回答
  • 2020-12-09 02:41

    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

    0 讨论(0)
提交回复
热议问题