Skip to content

Instantly share code, notes, and snippets.

@arindam89
Last active June 28, 2017 19:53
Show Gist options
  • Save arindam89/677ede6efb4642af465e4606d67fe91f to your computer and use it in GitHub Desktop.
Save arindam89/677ede6efb4642af465e4606d67fe91f to your computer and use it in GitHub Desktop.
Simple Mongo Query for DashBoard
var campuses_promise = campus.find().exec();
return campuses_promise.then(function(campuses){
var allPromises = [];
_.forEach(campuses, (campus) => {
allPromises.push(
visitor.count({campusId: campus._id}).exec().then((count) => {
campus.visitor_count = count;
}),
user.count({'ownership.campusId': campus._id}).exec().then((count) => {
campus.user_count = count;
}),
employee.count({campusId : campus._id}).exec().then((count) => {
campus.employee_count = count;
}),
userinapp.find({}).populate({path: 'userId',
model: 'user', select: 'ownership.campusId',
match: {'ownership.campusId': campus._id}})
.count()
.exec()
.then((count) => {
campus.user_in_app_count = count;
}),
attendance.find({}).populate({path:
'employeeId', model: 'employee', select: 'campusId',
match: {campusId: campus._id}})
.count()
.exec()
.then((count) => {
campus.employee_attendance = count;
})
)
});
return Promise.all(allPromises).then(() => { return campuses });
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment