I am trying to loop through something but first I need to do a mongo query to get the data for the loop my query is this:
AP.find({}, function(err, allAP) {
var ID = req.user.id;
if(err){
console.log(err);
} else {
res.locals.aps= allAP; // Set the data in locals
next();
}
});
I know I need to add something in the {}
part on line 1. How do I take req.user.id
and then only find documents with the author.id (see below)
author: {
id: {
type: mongoose.Schema.Types.ObjectId,
ref: "User"
},
email: String
}
Example document currently returned:
{ _id: 59e517230a892a26cb1b7635,
manufacturer: 'other',
model: 'Test Model',
bands: '2.4',
channel: 11,
notes: 'I am a test note for the first access point',
__v: 0,
author: { id: 59d7f98a77fcc221d6e3c93d, email: 'joe@example.com' } },