When I'm trying to push too large data into `mongoDb` I'm getting this error: `MongoError: document is larger than the maximum size 16777216`
I know, it is normal, but I can not catch this error, and my `node.js` process exits.
Can you tell me, how to catch this error?
example 1: can not catch the error, `node` process exits
var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/test');
mongoose.connection.on('error', function (err) {
console.log(err);
});
var Cat = mongoose.model('Cat', {name: Object});
setTimeout(function () {
var kitty = new Cat({
name: {
value: 'Zildjian',
data: (new Array(16 * 1024 * 1024)).join("x")
}
});
kitty.save(function (err) {
if (err) // ...
console.log('meow');
});
}, 1000);
Without the timeout I can catch the error:
example 2: error is caught, process doesn't exit
var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/test');
mongoose.connection.on('error', function (err) {
console.log(err);
});
var Cat = mongoose.model('Cat', {name: Object});
var kitty = new Cat({
name: {
value: 'Zildjian',
data: (new Array(16 * 1024 * 1024)).join("x")
}
});
kitty.save(function (err) {
if (err) // ...
console.log('meow');
});
I've tried to wrap my code into a `try...catch` but that doesn't caught the error either.