The DB has 9 users (collection 1). Each user can have 0 or 1 rsvps (collection 2). There are only 2 rsvps in the rsvps collection.
The following code returns 9 records. Even for the 2 users with rsvps, rsvp is an empty array [ ].
What am I doing wrong?
// Gets all Users' attendance information for the Home view.
return new Promise( (resolve, reject) => {
// Get all attendance database records using mongoose.
User.aggregate([{
$lookup: {
from: "rsvps", // collection name in db
localField: "_id",
foreignField: "userId",
as: "rsvp"
}
}
]).exec( (err, userList) => {
if (err) throw err;
console.log(userList);
});