问题
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 _id
s. 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.
来源:https://stackoverflow.com/questions/32660541/minimongo-errors-when-i-try-to-update-a-document-containing-an-array