Last active
June 28, 2017 19:53
-
-
Save arindam89/677ede6efb4642af465e4606d67fe91f to your computer and use it in GitHub Desktop.
Simple Mongo Query for DashBoard
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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