MongoDB文件大小限制

时间:2019-05-03 11:43:48

标签: mongodb

为什么我要存储大于16MB的BSON文档?

我使用不带GridFS的MongoDB 来存储图像二进制数据。 mongodb文档指出:The maximum BSON document size is 16 megabytes。但是我可以毫无问题地存储大型BSON文档。我通过回读存储的文档来再次检查,但没有文档损坏。 Large documents without corruption

_, err := itemdbConn.InsertOne(ctx, item)
if err != nil {
    log.Println(err)
    return
}

我希望mongo-go-driver在插入大文档时返回错误,但是没有。

编辑:source code评论中,我发现大小限制检查为不严格

/* Note the limit here is rather arbitrary and is simply a standard. generally the code works
   with any object that fits in ram.
   Also note that the server has some basic checks to enforce this limit but those checks are not
   exhaustive for example need to check for size too big after
     update $push (append) operation
*/
const int BSONObjMaxUserSize = 16 * 1024 * 1024;

/*
   Sometimes we need objects slightly larger - an object in the replication local.oplog
   is slightly larger than a user object for example.
*/
const int BSONObjMaxInternalSize = BSONObjMaxUserSize + (16 * 1024);

这意味着mongodb将随机返回错误或不返回错误,具体取决于操作。该注释仅提及 push 操作,因此我不知道它是否还会检查插入操作。我做了大约1000次这样的插入操作,没有任何错误...

0 个答案:

没有答案