更新集合中双嵌套数组中的对象

时间:2016-02-21 18:43:29

标签: mongodb meteor simple-schema

拥有此架构:

 Task = new SimpleSchema({
      _id: {
        type: String,
        regEx: SimpleSchema.RegEx.Id,
        autoValue: function(){ return Random.id(); }
      },
      title: {
        type: String,
        label: "Task title",
      }
    });

Card = new SimpleSchema({
  _id: {    
    type: String,
    regEx: SimpleSchema.RegEx.Id,
    autoValue: function(){ return Random.id(); }
  },
  tasks: {
    type: [Task],
    label: "Card tasks",
    optional: true
  }
});

ProjectSchema = new SimpleSchema({
  name: {
    type: String,
    label: "Project name"
  },
  cards: {
    type: [Card],
    label: "Project cards",
    optional: true
  }
});

我尝试使用此功能更新它,通过编辑的任务传递3个ID和一个对象:

    editTask : function(projectId,cardId,taskId,oTask) {

    if (! Meteor.userId()) {
        throw new Meteor.Error("not-authorized");
    }

    check(projectId, String);
    check(cardId, String);
    check(taskId, String);
    check(oTask, Object);

    Projects.update({
        _id: projectId,
        cards: {
            $elemMatch : {
                _id: cardId,
                tasks : {
                    _id : taskId
                }
            }
        }
    },
    {
        $set: {"tasks.$.Task": oTask}
    });
    }

错误说:当修饰符选项为true时,验证对象必须至少有一个运算符。 据我所知,错误意味着$ set:{" tasks。$。Task":oTask}它没有正确指向。

我也试过:$ set:{" cards.tasks。$。Task":oTask},$ set:{" cards。$。tasks": oTask}

0 个答案:

没有答案