1

I'm having trouble updating an array that is contained in a document using angular-meteor. Minimongo throws an error documentMatches needs a document.

The document that throws this error on update is shown below. One thing it contains is an array of _ids. This array contains the display order of some certain documents. It looks like this:

{
  _id:"...",
  profileQuestions:{
    profileQuestionsOrder:["jqKMp7rzsZApauwYE","jakehILKehpkdhj"]
  }
}

I have attached this using $scope.meteorObject to a variable called $scope.settings. When I remove an item from this array and then save with .save(), I get the error. The funny thing is, when I add an item to the array, and then save, there is no problem! I can also add other keys to the settings object with no issue. It's just the array that causes problems.

I used chrome's debugger to see what was going on when the error was thrown, and here is the code that throws the error:

  documentMatches: function (doc) {
    if (!doc || typeof doc !== "object") {
      throw Error("documentMatches needs a document");
    }
    return this._docMatcher(doc);
  },

What's crazy is that doc here is actually the first item in the profileQuestionsOrder array - it is simply a string containing a document id. It seems like miniMongo is getting confused about this array. I can put in any other property, and it has no error. But when I remove an item from this array, it has problems.

By the way, when I do not save the object to the db, I can see that it was correctly altered, splicing one element out of the array.

user3413723
  • 11,147
  • 6
  • 55
  • 64
  • where's the code where you try to update the doc? – Keith Nicholas Sep 19 '15 at 00:08
  • In Angular-meteor, you just write $scope.settings.save(), and it's supposed to save it all. I think there may be a bug in the $meteorObject code. I changed to use a collection instead and it works. – user3413723 Sep 19 '15 at 01:30

0 Answers0