1

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}

Borra
  • 23
  • 7
  • Not a tested theory, but it's possible that your schemas are not defined properly. You're using `Task` in the `Card` schema before `Task` is defined, and `Card` in the `ProjectSchema` before `Card` is defined. SimpleSchema could be ignoring some of the properties when parsing the query because the paths don't really exist. – Brian Shamblen Feb 21 '16 at 19:59
  • oh, sorry about that, it actually is in the right order in my code, I just pasted it on that order for readability, I'll fix it – Borra Feb 21 '16 at 23:37
  • You can only ever return the matched index of the "outer" array only, so looking to match the position of the "inner" array is not possible. Well documented under the [positional `$`](https://docs.mongodb.org/manual/reference/operator/update/positional/) operator. Ideal don't "nest" arrays, and flatten the structre into single array entries at most. – Blakes Seven Feb 22 '16 at 01:06
  • Thanks, I read that in the documentation but didn't figure out it meant I can't search at all into a deeper array. I'll try putting the tasks on the first level. – Borra Feb 22 '16 at 09:14

0 Answers0