I'm migrating my Mongoose code to use Promises to avoid The Pyramid of Doom. I want to break the Promise's chain on a certain point, but I don't know how to do it. Here's my code:
var data = {};
People.find({}).exec()
.then(function(people) {
if (people.length == 0){
// I want to break the chain here, but the console.log() gets executed
res.send('No people');
return;
}
data['people'] = people;
return Events.find({
'city': new mongoose.Types.ObjectId(cityID)
}).lean().exec();
}).then(function(events) {
console.log('here');
data['events'] = events;
res.send(data);
});