执行 mongo 命令时出错

getting error while executing mongo command

我使用以下命令创建了一个集合:

db.device_states.documentKey.insert({"device":"nest_kitchen_thermo"})

当我尝试执行以下命令时出现错误:

db.device_states.watch( {
     $match: {
             "documentKey.device": {
                   $in : [ "nest_kitchen_thermo"]
             },
             operationType: "insert"
     }
});

syntax ERROR: missing:after property id:

更新后的合集如下所示:

{ 
    _id: <resume_token>,
    operationType: 'insert',
    ns: {db:'example',coll:"device_states"},
    documentKey: { device:'nest_kitchen_thermo'},
    fullDocument: { 
       _id : ObjectId(),
       device: 'nest_kitchen_thermo',
       temp: 68
    }
}

在Mongoshell中没有这样的查询属性watch$match 是聚合管道的一部分,应该在聚合操作中使用。

修改后的查询(Mongo Shell)是

db.device_states.documentKey.aggregate([
  { $match:
    { 
      "device": { $in: ["nest_kitchen_thermo"] }, 
      operationType: "insert"
    }
  }
]);