Querying with joins & filters in Mongoose
You were almost there, you just needed the right $match
query which follows:
ubBike.aggregate([ { "$match": { "cust": req.query._id } }, { "$lookup": { "from": "appos", "localField": "_id", "foreignField": "bike", "as": "appointments" } }, { "$match": { "appointments.status": { "$ne": "Booked" } } }]).exec(function(err, bikes){ if(err) throw err; res.send(bikes); });