Mongodb 使用对象字段更新文档

Mongodb 使用对象字段更新文档,mongodb,object,mongodb-query,Mongodb,Object,Mongodb Query,我是MongoDB的新手,从它的文档中学习,但找不到使用MongoDB shell更新文档字段的方法 当我尝试在任一字段中插入“cancellation”对象时,查询工作正常 db.inventory.update({}, { $set : { "cancellation": { {"date" : new Timestamp()}, {"reason" : "null"} } } }

我是MongoDB的新手,从它的文档中学习,但找不到使用MongoDB shell更新文档字段的方法

当我尝试在任一字段中插入“cancellation”对象时,查询工作正常

db.inventory.update({},
{
  $set : { "cancellation": 
          { 
           {"date" : new Timestamp()},
           {"reason" : "null"}
          }
         }
 },
{upsert : false,multi : true})
它表明

“SyntaxError:无效的属性id@(外壳)”


执行此查询时,您的查询是错误的。试试这个:

db.inventory.update({},{$set : { "cancellation": 
      { 
       "date" : new Timestamp(),
       "reason" : "null"
      }
     } },{upsert : false,multi : true})