Answer the question
In order to leave comments, you need to log in
Mongoose: how to save multiple documents with one request?
There is a code that should save several documents at once:
app.post('/createTestUsers', (request, response) => {
let data = [
{name: 'Mike'},
{name: 'Tom'}
];
User.collection.insert(data, (err, doc) => {
if(err) {
console.log('/createTestUsers | POST | Error was occurred');
console.log(err.errmsg);
response.status(403).send(err.errmsg);
}
if(!err) {
response.status(200).send(amount + ' users was created');
}
});
});
E11000 duplicate key error collection: contacts_ng2.users index: login_1 dup key: { : null }
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question