Pulling objects from array [solved]

Hi,

I lack the knowledge of pulling an specific object from an array and hope someone could help me out.

The relevant part of my collection document looks like this:

"mo": [
    {
      "name": "Name1",
      "day": "Day2",
      "server": "Server1",
      "eventTime": "20:00",
      "rank": 0,
      "location": "Location1",
      "owner": "111222"
    },
    {
      "name": "Name2",
      "day": "Day2",
      "server": "Server2",
      "eventTime": "20:00",
      "rank": 0,
      "location": "Location2",
      "owner": "222333"
    }

So if I would like to pull the object with the name “Name2” how exactly could I target it? I can do it with String-arrays just fine by naming the array-element like so:

   ChatMeta.update({character: charOwner}, {
     $pull: {
       lastWhisp: char,   
     },
    },
    );

But I don’t quite get how to name a specific object in a similar manner.

Thanks for any help!

You haven’t posted enough info on your individual situation so it’s hard to say how we can help. However if you want to pull an object from an array of objects you can use $elemMatch. It’s very important that the “key” in the $pull object is the field that is an array and the value of the $pull object is whatever you want to remove (in this case it’s an $elemMatch).

Meteor.users.update({'emails.verified': false}, {
    $pull: {'emails': {$elemMatch: {'verified': false}}}
})

Thank you, this hint was enough to make it work properly enough, I think.

I did it like this:

    Events.update({'do.name': name}, { $pull: { 'do':  {'name': name} } });