mongodb更新集合错误

files本身是一个数组,想根据files中的id进行更新files中的status属性,并添加一个新对象,名字为reviewUsers,

  const newFile = {
    userId:userId,
    pathologyId:fileId,
    groupId:groupId,
    userName:userName,
};
MongoClient.connect(mongoURL, function (err, db) {
    if (err) throw err;
    const dbo = db.db("path-cloud");
    dbo.collection('AnnotationFileGroups').update({
        _id: groupId,
        'files.id': fileId
    }, {$addToSet: {'files.$.status': 2,'files.$.reviewUsers':newFile}}, (e, result) => {})

现在是这么写的提示错误Cannot apply $addToSet to non-array field. Field named 'status' has non-array type int

阅读 2.4k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进