I'm a novice developer using node and mongoose, and wondering what the best way of chaining queries with mongoose. I'm doing like below, it's not working.
User.findByIdAndUpdate(req.params._id, user, { upsert: true })
.exec((err, updatedUser) => {
if (addedCollections) {
return User.findByIdAndUpdate(req.params._id, { $push: { _collections: { $each: addedCollections } } }, { upsert: true }).exec();
}
return new Query;
})
.exec(() => {
return User.findById(req.params._id).populate('_collections');
})
.exec((err, user) => {
res.json({ user });
})
How can I do chain multiple queries?