0

This is my schema:

{
_id: "FJwSEMdDriddXLKXh"
name: "t"
number: "5"
owners: [
          {
           _id: 1,
           name: "Name",
           address: "Address",
           type: "Type",
           gender: "Gender",
           notes: []
          }
    ]
}

and on click I would add fields inside owners nested notes array. This is my Meteor template events:

Template.owners.event({
  'click #addNoteToOwner' : function(event, template){
      event.preventDefault();
      Territories.update({_id: template.data._id, owners: this._id}, {$push : {'owners.$.notes':  {title:"First Title"}}})
    }
})

If I try to update the doc, the following console errorT appear:

Uncaught Error: Not permitted. Untrusted code may only update documents by ID. [403]

Is my syntax correct? How can I update this nested array?

Thanks!

1 Answer 1

3

There is mistake in your query in owners field:

Territories.update({
         _id: template.data._id,
         owners: {
             $elemMatch: {
                 _id: this._id
             }
         },
         {
             $push: {
                 'owners.$.notes': {
                     title: "First Title"
                 }
             }
         })

You won't be able to update directly from client side, because you use owners field and only _id is allowed. To solve this you can update using Meteor.methods and call that method from client side.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.