【问题标题】:MongoDB not okForStorage errorMongoDB not okForStorage 错误
【发布时间】:2013-12-10 21:58:02
【问题描述】:

关于这个错误,我环顾四周,似乎 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" }
  ]
  }
}

【问题讨论】:

  • 您能否发布一个将问题重现为 github 问题的代码示例。

标签: javascript node.js mongodb


【解决方案1】:

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

【讨论】:

  • 对于带句点的键遇到同样的问题。有什么办法解决这个问题吗?
  • MongoDB 不允许在字段名称中使用 .$ - 它们具有特殊的语义含义。见docs.mongodb.org/manual/reference/limits/#naming-restrictions
  • 我在使用 EJSON $date 键时遇到了同样的问题,我没有转换回普通的 JSON。
【解决方案2】:

所以对于遇到同样错误的人来说: 这是因为我包含了 _id,Mongo 显然不喜欢它

【讨论】:

【解决方案3】:

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

 "$$hashKey":"021"

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

$scope.ngObjFixHack = function(ngObj) {
    var output;

    output = angular.toJson(ngObj);
    output = angular.fromJson(output);

    return output;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-10
    • 2013-12-24
    • 2013-02-07
    • 1970-01-01
    • 2013-02-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多