MongoDB-MongoError:更新后的结果文档大于16777216

lau*_*kok 2 mongoose mongodb node.js express

我的ExpressJS应用中出现此错误:

Error updating stream: MongoError: Resulting document after update is larger than 16777216
_http_server.js:192
    throw new RangeError(`Invalid status code: ${statusCode}`);
Run Code Online (Sandbox Code Playgroud)

因此,我认为我的文档已超出限制。

如何增加限额?

我从这个答案中得到了这个链接。但是如何在我的应用程序中使用它?我该如何开始?

我正在使用猫鼬来存储和检索我的数据。

有什么想法/提示吗?

这是我在猫鼬中的文档架构:

var mongoose = require("mongoose");
var mongoosePaginate = require('mongoose-paginate');

// Declare schema
var streadatamSchema = new mongoose.Schema({
    user_id: {
        type: String,
        required: true
    },
    title: {
        type: String,
        required: true
    },
    description: {
        type: String,
        required: true
    },
    data: {
        type: Object
    },
    entries_number: {
        type: Number,
        default: 0
    },
    last_entry_at: {
        type: Date
    },
    created_at: {
        type: Date,
        default: Date.now,
        index: 1 // Note 1
    },
});

streamSchema.plugin(mongoosePaginate);

// Export schema
// Model.paginate()
mongoose.model("Stream", streamSchema);
Run Code Online (Sandbox Code Playgroud)

我认为这是该data字段现在包含太多数据的原因。

rsp*_*rsp 5

因此,我认为我的文档已超出限制。

如何增加限额?

Mongo中的大小限制在源代码中进行了硬编码

/* 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
     various db.eval() type operations
*/
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 );

const int BufferMaxSize = 64 * 1024 * 1024;
Run Code Online (Sandbox Code Playgroud)

更改它的唯一方法是更改​​源代码并从源代码构建您自己的Mongo版本。

  • 2023 年了,这仍然是一个问题:'( (2认同)