2

I have a collection like this

{
    _id: "qex6zPLgigq4KGpFP",
    active: true,
    name: "event name",
    questions: [{
        _id: "cff4cc7f1ae67282f1ea142b",
        createdBy: "izRFAkhxgemihkRMF",
        likes: 2
    }, {
        _id: "2cf23241ca456703f50a9ce4",
        createdBy: "izRFAkhxgemihkRMF",
        likes: 0
    }]
}

and I initialize my collection in my Meteor application like this:

  Events = new Mongo.Collection("events");

Now I want to remove a subdocument from the 'questions' array and it works in the shell with

db.events.update({_id:"qex6zPLgigq4KGpFP"}, {$pull: {'questions': {_id:"cff4cc7f1ae67282f1ea142b"}}})

but NOT in Meteor by calling

Events.update({_id:"qex6zPLgigq4KGpFP"}, {$pull: {'questions': {_id:"cff4cc7f1ae67282f1ea142b"}}})

The return value is always '1', but the document is still there. It's confusing. Any ideas?

Community
  • 1
  • 1
greyno
  • 91
  • 8
  • Meteor's Mongo hasn't exactly duplicated all the functions of actual Mongo. Perhaps this will help? http://stackoverflow.com/questions/19362539/meteor-pull-remove-from-array - Looks like you have to pull the entire object. – fuzzybabybunny Jun 24 '15 at 01:45
  • @greyno the [docs](http://docs.mongodb.org/v2.6/reference/operator/update/pull/) seem to indicate that an exact match of the document is required, however I tried reproducing your example with meteor 1.1.0.2 and it pulled the correct question from the list. What version of meteor are you using? How are you testing that the `event` document was not affected? – David Weldon Jun 24 '15 at 05:12
  • @greyno Is this on the client or on the server? On the server, it's sent directly to mongo. On the client, it uses a meteorish mongo: minimongo instead. – Tarang Jun 24 '15 at 06:16
  • @David I am using meteor 1.1.0.2 as well.. I am testing by noticing that the question is still listed on my page. It disappears by entering the shell command. – greyno Jun 24 '15 at 11:13
  • @Akshat it is on the server, but it does not work on client either. – greyno Jun 24 '15 at 11:15
  • @fuzzybabybunny does not work either... I just don't get it.. – greyno Jun 24 '15 at 11:34
  • @greyno Well, this is strange. I'm able to `$pull` it successfully out of my Mongo when called from the client, and I didn't even need to make an exact match of the document - all that was needed was the `_id`. I'm using GenghisApp to confirm it has been removed on the server and `Events.find().fetch()` in Chrome to confirm it has been removed on the client. – fuzzybabybunny Jun 24 '15 at 16:02
  • I'm using METEOR@1.1.0.2 meteor-platform@1.2.2 minimongo@1.0.8 mongo@1.1.0 – fuzzybabybunny Jun 24 '15 at 16:04
  • Thank you all for your great effort! I am fairly new to this and the problem was my attached schema.. still have to figure out what's wrong with it. – greyno Jun 24 '15 at 21:20

0 Answers0