I have a collection with organizations. Each organization has members. I want to run query to check if a user is a member of that organization.
I tried this:
mongoose.model('organization').find({orgId: paramOrgId}, function(err, organization){
organization.find({'members.user':req.user._id}, function(err, user){
if(!user) res.send(401) //The user is not a member in organization
if(user) res.send(200);
});
}
return res.send(401);
});
Apparently you don't have 'find' on callback. How should I do this instead?
Example of organization doc:
> db.organizations.find().forEach(printjson);
{
"_id" : ObjectId("5381d5d11409f125475fcc90"),
"orgId" : 5,
"title" : "ExampleCorp",
"members" : [
{
"tier" : 1,
"user" : ObjectId("5381d5d11409f125475fcc8c")
},
{
"tier" : 2,
"user" : ObjectId("5381d5d11409f125475fcc8d")
},
{
"tier" : 3,
"user" : ObjectId("5381d5d11409f125475fcc8e")
}
]
}