Using mongoose to add new field to existing document in mongodb through update method

后端 未结 3 1582
南笙
南笙 2021-02-20 07:45

I\'m trying to update a mongodb document with mongoose in node.js

When the field exists, the update works, but if the field does not exist, the update will not work.

3条回答
  •  执念已碎
    2021-02-20 08:32

    Try the following code:

    User.update(
         {uid: 'uid'}, 
         {vehicle_status : 'vehicleSatus' },
         {multi:true}, 
           function(err, numberAffected){  
           });
    

    Also, make sure that you add vehicle_status to the schema.

提交回复
热议问题