updating objects in double nested arrays in a collection

218 Views Asked by At

Having this 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
  }
});

I'm trying to update it with this function, passing the 3 ids and an object with the editted task:

    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}
    });
    }

Error says: when the modifier option is true, validation object must have at least one operator. As far as I know that error means the $set: {"tasks.$.Task": oTask} it's not pointing correctly.

I've also tried: $set: {"cards.tasks.$.Task": oTask},$set: {"cards.$.tasks": oTask}

0

There are 0 best solutions below