MongoDB not okForStorage error

MongoDB not okForStorage error

本文关键字:error okForStorage not MongoDB      更新时间:2023-09-26

关于这个错误,我已经看了很多,似乎Mongo不会接受更新中的.$,但我仍然收到此错误

{ [MongoError: not okForStorage]
  name: 'MongoError',
  err: 'not okForStorage',
  code: 12527,
  n: 0,
  connectionId: 18,
  ok: 1 }

这是我正在更新的对象:

{
status: "open",
type: "item",
parentId: "4fa13ba2d327ca052d000003",
_id: "4fa13bd6d327ca052d000012",
properties: {
  titleInfo: [
   { title: "some item" }
  ]
  }
}

我正在将其更新为:

{
fedoraId: 'aFedoraLib:438',
status: "closed",
type: "item",
parentId: "4fa13ba2d327ca052d000003",
_id: "4fa13bd6d327ca052d000012",
properties: {
  titleInfo: [
   { title: "some item" }
  ]
  }
}

我刚刚遇到的另一个可能的原因:存储一个在字符串键中具有句点的对象。

因此,对于遇到相同错误的人来说:这是因为我包含了蒙戈显然不喜欢的_id

我在尝试使用此键值对保存 JSON 结构(直接来自 AngularJS 应用程序)时遇到了此错误:

 "$$hashKey":"021"

仅删除该键即可解决问题。对于其他使用Angular的人来说,调用Angular的内置angular.toJson客户端似乎消除了$hashkey美元的密钥。从他们的论坛:

$scope.ngObjFixHack = function(ngObj) {
    var output;
    output = angular.toJson(ngObj);
    output = angular.fromJson(output);
    return output;
}