0

From the client, I am able to pass the relevant _id (variable id is JPDCv6Wn6D94KSzMD for this example) of the particular object onto the method, along with a context variable that contains some words. I then wish to set the 'context' field with the context variable.

The summary object is located in meteor.user.profile

summary: Object
        _id: "JPDCv6Wn6D94KSzMD"
        context: ""

The method: (the method attempts to update the 'summary' object but the function is not correct)

Meteor.methods({
contentUpdate: function (context, id){
    Meteor.users.update({_id:this.userId, //some function)}
}
});

The update method is what I'm having trouble with.

Meteor.user(); console log:

Meteor.user();
  Object {_id: "YZEBzkGZsny668N8o", emails: Array[1], profile: Object, username: "Mr.A"}
    _id: "YZEBzkGZsny668N8o"
    emails: Array[1]
    profile: Object
       name: "Mr A"
       summary: Object
          _id: "JPDCv6Wn6D94KSzMD"
          context: ""
        __proto__: Object
      __proto__: Object
    username: "Mr.A"
   __proto__: Object
meteorBuzz
  • 3,110
  • 5
  • 33
  • 60

1 Answers1

0

From what I understand concerning your question, you need to do this:

Meteor.users.update({_id:this.userId, 'profile.objectId': id},{$set:{'profile.$.text' : text}});

See additionally: MongoDB - Update objects in a document's array (nested updating)

Community
  • 1
  • 1
Nate
  • 1,875
  • 15
  • 27
  • I have updated the question to show where these fields are located. At the moment the code is not performing the update – meteorBuzz Oct 23 '14 at 14:06
  • yes, sorry I just changed the field values, so the code earlier did correspond to the values respectively – meteorBuzz Oct 23 '14 at 14:17
  • 'context' is a field within the summary object. The summary object is identified by the _id: – meteorBuzz Oct 23 '14 at 14:35
  • I replaced the id variable with the actual id value and the update does not take place. – meteorBuzz Oct 23 '14 at 15:08
  • @CodeCandy do a `Meteor.user()` in your client console(browser console) and add that logged output object to your question please. – Nate Oct 23 '14 at 15:28