最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - MongoDB not okForStorage error - Stack Overflow

programmeradmin3浏览0评论

I've looked around quite a bit concerning this error, it seems that Mongo won't accept a . or a $ in an update, yet I still get this error

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

This is the object I'm updating:

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

And I'm updating it to:

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

I've looked around quite a bit concerning this error, it seems that Mongo won't accept a . or a $ in an update, yet I still get this error

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

This is the object I'm updating:

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

And I'm updating it to:

{
fedoraId: 'aFedoraLib:438',
status: "closed",
type: "item",
parentId: "4fa13ba2d327ca052d000003",
_id: "4fa13bd6d327ca052d000012",
properties: {
  titleInfo: [
   { title: "some item" }
  ]
  }
}
Share Improve this question asked May 3, 2012 at 9:28 QuirijnGBQuirijnGB 8191 gold badge9 silver badges18 bronze badges 1
  • can you post a code example reproducing the issue as a github issue please. – christkv Commented May 15, 2012 at 8:29
Add a comment  | 

3 Answers 3

Reset to default 12

Another possible cause I just ran into: storing an object which has periods in the string keys.

So for people getting the same error: It's due to the fact that I was including the _id, which Mongo doesn't like apparently

I ran into this error when trying to save a JSON structure with this key-value pair (coming straight out of an AngularJS app):

 "$$hashKey":"021"

Removing just that key fixed the problem. For others using Angular, it looks like calling Angular's built-in angular.toJson client-side eliminates the $$hashkey keys. From their forums:

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

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

    return output;
}
发布评论

评论列表(0)

  1. 暂无评论