Minimongo errors when I try to update a document containing an array

混江龙づ霸主 提交于 2019-12-24 17:23:52

问题


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.

来源:https://stackoverflow.com/questions/32660541/minimongo-errors-when-i-try-to-update-a-document-containing-an-array

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!