MongoError: attempt to write external buffer borders

I have simple node.js code that tries to retrieve an object, fill in a 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 upgrade, the mango throws:

 MongoError: attempt to write outside buffer bounds. 

Can someone explain what I'm doing wrong?

+8
mongodb mongodb-query
source share
1 answer

This error usually occurred when trying to save / update a document with huge information / illegal type information.

In mongodb, the maximum BSON document size is 16 megabytes. Below is the link.

+1
source share

All Articles