如何使用node.js插入200k对象,mongodb?

时间:2016-12-01 12:14:00

标签: javascript node.js mongodb

我有20万用户。我想通过node.js插入。如何修改控制器功能?

exports.create = function(req, res, next) {
    var newUser = new User(req.body);
    newUser.provider = 'local';
    newUser.role = 'user';
    newUser.save(function(err, user) {
        if (err) 
            return validationError(res, err);
        var token = jwt.sign({_id: user._id }, config.secrets.session, { expiresInMinutes: 60*5 });
        res.json({ token: token });
    });
};

我试过,但是我收到了这样的错误

  Error: request entity too large
    at readStream (Test\node_modules\raw-body\index.js:196:17)
    at getRawBody (Test\node_modules\raw-body\index.js:106:12)
    at read (Test\node_modules\body-parser\lib\read.js:76:3)
    at jsonParser (Test\node_modules\body-parser\lib\types\json.js:127:5)
    at Layer.handle [as handle_request] (Test\node_modules\express\lib\router\layer.js:82:5)
    at trim_prefix (Test\node_modules\express\lib\router\index.js:270:13)
    at Test\node_modules\express\lib\router\index.js:237:9
    at Function.proto.process_params (Test\node_modules\express\lib\router\index.js:312:12)
    at Test\node_modules\express\lib\router\index.js:228:12
    at Function.match_layer (Test\node_modules\express\lib\router\index.js:295:3)
    at next (Test\node_modules\express\lib\router\index.js:189:10)
    at urlencodedParser (Test\node_modules\body-parser\lib\types\urlencoded.js:100:7)
    at Layer.handle [as handle_request] (Test\node_modules\express\lib\router\layer.js:82:5)
    at trim_prefix (Test\node_modules\express\lib\router\index.js:270:13)
    at Test\node_modules\express\lib\router\index.js:237:9
    at Function.proto.process_params (Test\node_modules\express\lib\router\index.js:312:12)

0 个答案:

没有答案