0

I created a child array of objects in a document. Each of these array objects have:

children: [
    {
        _id: ObjectID("lkajsdflkajdsf"),
        title: "Something"
    }, ...
]

I'm getting ObjectId undefined error when trying to update a document:

Category.update(
    { "_id": "C2Rcjivw96htJSHRq", "children._id":  ObjectId("1c46382a25d3888165dd338a") },
    { "$set": { "children.$.title": "Hello World" }}
);

As you can see I'm attempting to update a specific array object by it's associated _id. This does not work. I was reading this thread: Meteor collection update with traditional id

But it's a little outdated, and I'm also getting errors when trying to use it.

Is there a solid method for handling things in this fashion? I can do this in Mongo shell with no problem, but not through Meteor methods.

Thanks!

Community
  • 1
  • 1
user1447679
  • 3,076
  • 7
  • 32
  • 69
  • http://docs.mongodb.org/manual/reference/operator/update/set/#up._S_set also where do you update collection , server/client? – yoK0 Oct 06 '14 at 00:17
  • In this case the server because I'm passing multiple selectors. Tried on the client and it wouldn't allow me. – user1447679 Oct 06 '14 at 00:30
  • @yoK0 The problem here is my _id field inside the child array is an Object, not a string. I'm getting ReferenceError: ObjectID is not defined. – user1447679 Oct 06 '14 at 00:31
  • Use .toString method – yoK0 Oct 06 '14 at 03:06
  • I'm actually running into a ton of problems when dealing with ObjectId type. When generating the categories I changed to new Meteor.Collection.ObjectID()._str to just use it as a string. Now I'm studying up on the dangers of this since there's no technical duplicate checking... not that the chances of duplicate strings generated from that are common... just still learning. – user1447679 Oct 06 '14 at 03:42

0 Answers0