JS工具:mongodb Payload Too Large 与 使用教程

  • 问题

Error: 'Request entity too large'. How to increase bodyParser limit outside meanio module?
  • 方案

Try to apply this in your app.js instead.

app.use(bodyParser.json({limit: '50mb'}));
app.use(bodyParser.urlencoded({limit: '50mb'}));

Hope this help!

insert和save函数到底有什么区别呢?

由上面可以看出,save函数实际就是根据参数条件,调用了insert或update函数.如果想插入的数据对象存在,insert函数会报错,而save函数是改变原来的对象;如果想插入的对象不存在,那么它们执行相同的插入操作.

> db.user.insert
function (obj,_allow_dot) {
    if (!obj) {
        throw "no object passed to insert!";
    }
    if (!_allow_dot) {
        this._validateForStorage(obj);
    }
    if (typeof obj._id == "undefined" && !Array.isArray(obj)) {
        var tmp = obj;
        obj = {_id:new ObjectId};
        for (var key in tmp) {
            obj[key] = tmp[key];
        }
    }
    this._db._initExtraInfo();
    this._mongo.insert(this._fullName,obj);
    this._lastID = obj._id;
    this._db._getExtraInfo("Inserted");
}
> db.user.save
function (obj) {
    if (obj == null || typeof obj == "undefined") {
        throw "can't save a null";
    }
    if (typeof obj == "number" || typeof obj == "string") {
        throw "can't save a number or string";
    }
    if (typeof obj._id == "undefined") {
        obj._id = new ObjectId;
        return this.insert(obj);
    } else {
        return this.update({_id:obj._id},obj,true);
    }
}

注意其中的(insert还是update,取决于obj._id == "undefined")

    if (typeof obj._id == "undefined") {
        obj._id = new ObjectId;
        return this.insert(obj);
    } else {
        return this.update({_id:obj._id},true);
    }

obj代表需要更新的对象,如果集合内部已经存在一个和obj相同的"_id"的记录,Mongodb会把obj对象替换集合内已存在的记录,如果不存在,则会插入obj对象。

2.$set

用法:{$set:{field:value}}

作用:把文档中某个字段field的值设为value

示例: 把chenzhou的年龄设为23岁

1. \> db.students.find()  
2. { "_id" : ObjectId("5030f7ac721e16c4ab180cdb"),"name" : "chenzhou","age" : 27 }  
3. \> db.students.update({name:"chenzhou"},{$set:{age:23}})  
4. \> db.students.find()  
5. { "_id" : ObjectId("5030f7ac721e16c4ab180cdb"),"age" : 23 }  
6. \>  

从结果可以看到,更新后年龄从27变成了23

相关文章

文章浏览阅读552次。com.mongodb.MongoQueryException: Quer...
文章浏览阅读635次,点赞9次,收藏8次。MongoDB 是一种 NoSQ...
文章浏览阅读2.1k次。和。_mongodb 日期类型
文章浏览阅读1.7k次。Scalestack等客户期待使用MongoDB Atla...
文章浏览阅读970次。SpringBoot整合中间件mongodb、ES_sprin...
文章浏览阅读673次。MongoDB 简介_尚医通sql