问题
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