node.js - MongoError : attempt to write outside bu

我有一个简单的 node.js 代码,它试图获取对象、填充字段然后更新同一个对象:

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);
       });

   });
});

当我尝试更新时,mongo 正在抛出:

MongoError: attempt to write outside buffer bounds. 

谁能解释我做错了什么?

最佳答案

此错误通常在尝试保存/更新包含大量信息/非法类型信息的文档时发生。

在 mongodb 中,最大 BSON 文档大小为 16 兆字节。这里是 link了解更多详情。

关于node.js - MongoError : attempt to write outside buffer bounds,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29918668/

相关文章:

mongodb - Mongorestore:ns 名称太长,最大大小为 128

regex - MongoDB 中 $cond 中的“like”或 $regex 查询

mongodb - 通过 Grails 域标准在事件光标中发现 Mongo CursorNotFou

mongodb - MongoDB中的有向无环图设计模式

python - Mongo 连接从未发布 - Django 和 Mongoengine 使用 ge

mongodb - 一个集合中的许多文档与多个集合

node.js - 2服务器负载均衡 Node js应用设置中的Elasticsearch部署

javascript - 使用 Javascript/Node.js 在代码中执行 mongoimp

php - 如何安装 PHP 的 MongoDB 驱动程序 — "pecl install mong

node.js - 如何使用一个属性的值作为另一个属性的默认值?