Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MongoError: attempt to write outside buffer bounds

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?

like image 359
J.D. Avatar asked Apr 28 '15 11:04

J.D.


1 Answers

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.

like image 90
vineet Avatar answered Oct 06 '22 00:10

vineet