MongoDB - MongoError:更新后生成的文档大于16777216

时间:2017-03-23 21:35:18

标签: node.js mongodb express mongoose

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

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

所以我认为我的文件超出了限制。

如何增加限额?

我从link获得此answer。但是我如何在我的应用程序中使用它?我该如何开始?

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

任何想法/提示?

这是我在mongoose中的文档架构:

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);

我认为data字段现在有太多数据。

1 个答案:

答案 0 :(得分:2)

  

所以我认为我的文件超出了限制。

     

如何增加限额?

Mongo的大小限制为hardcoded in the 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
     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;

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