Closed gaand closed 7 years ago
@gaand are you referring to this code, and if so, was this what you were looking for? Do I need that seconde (nested) .catch()
or will my first catch catch it?
db.once('open', function () {
loadPeople()
.then((people) => {
// Below is the way to insert that bypasses mongoose validations
// Person.collection.insert(people);
// This inserts and runs the documents through mongoose validations
- Person.insertMany(people, function(err, docs) {
- if (err) {
- throw err;
- }
- console.log(docs.length + ' documents inserted');
- done();
- });
+ Person.insertMany(people)
+ .then((docs)=>{
+ console.log(docs.length + ' documents inserted');
+ })
+ .catch(console.error);
})
.catch(console.error);
});
I believe this suffices:
db.once('open', function () {
loadPeople()
.then(people =>
Person.insertMany(people)
.then(docs =>
console.log(docs.length + ' documents inserted')
)
)
.catch(console.error);
});
@gaand What about this? (from @payne-chris-r):
db.once('open', function () {
loadPeople()
.then(Person.insertMany)
.then(docs =>
console.log(docs.length + ' documents inserted')
)
.catch(console.error);
});
Fixed:
db.once('open', function () {
loadPeople()
.then(Person.insertMany)
.then(docs =>
console.log(docs.length + ' documents inserted')
)
.catch(console.error)
.then(done);
});
@gaand I thought done
went last, am I incorrect?
Done is last.
Rather than passing a callback.