MongoDB RangeError: attempt to write outside buffer bounds

纵饮孤独 提交于 2021-02-09 01:25:08

问题


I am not receiving this error all the time but for specifics arrays. I am trying to insert a JSON object into mongodb collection using node.js mongodb native driver. This JSON object has couple of string attributes and a big string array attribute. Array could have thousands of string items. My JSON looks like this

{   
    FileName :"504-2345.txt",
    SIMs :["8931440400012","893144040001","4000130360507",.........]
}

Any idea when MongoDB throws RangeError: attempt to write outside buffer bounds? Please suggest

Below method insert the data in Mongodb

 Insert: function (data, type, callback) {

    MongoClient.connect(url, function (err, db) {
        // logger.log("info","Before Inserting documents into "+type +" documents =>"+data.length);

        if (err) {
            logger.log("error", err);
        }

        var collection = db.collection(type);
        // Insert some documents
        collection.insertOne(data, function (err, result) {

            if (err) {
                logger.log("error", " Error for Data while inserting  Error =" + err);
            }
            else {
                db.close();
                if (result.ops) {
                    callback(err, result.ops[0]);
                }
            }


        });


    });
},

回答1:


The document should be less than 16mb. Otherwise it get exceptions.You can refer this link for more details. You can use gridFs in here.



来源:https://stackoverflow.com/questions/37078342/mongodb-rangeerror-attempt-to-write-outside-buffer-bounds

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!