I have a simple node.js code that is trying to fetch the object, populate the field and then update the same object :
var MongoClient = require('mongodb').MongoClient
, Db = require('mongodb').Db
, Server = require('mongodb').Server
, ObjectID = require('mongodb').ObjectID;
var db = new Db('testing', new Server('localhost', 27017));
db.open(function(err, db){
var Users = db.collection('users');
Users.find({code : {$exists : false} }, {email : 1}, function(err, users){
users.forEach(function(user){
var code = generateCode();
var userID = user._id;
Users.update({ _id : user._id }, {$set : {code : code } }, function(err, results){
if (err) console.log(err);
else console.log(results);
});
});
});
When I try to do an update mongo is throwing:
MongoError: attempt to write outside buffer bounds.
Can someone explain what am I doing wrong?
This error generally occurred when try to save/update document with huge information/illegal type information.
In mongodb, the maximum BSON document size is 16 megabytes. Here is link for more details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With