I'm simply trying to submit a query to MongoDB using MEAN.js. I want to get the number of users stored in Mongo. (the count of all users who have registered).
I'm working with a giant mess of a MEAN.js website, written by students, that is made up of thousands of .js files. I have identified that two files are likely related:
app/controllers/users/users.authentication.server.controller.js
which has functions like exports.signup = function(req, res) {...} and exports.signin = function(req, res, next) {...} in it.
I added:
exports.userCount = function(req, res) {
// use mongoose to get the count of Users in the database
User.count(function(err, count) {
// if there is an error retrieving, send the error. nothing after res.send(err) will execute
if (err)
res.send(err)
res.json(count); // return return the count in JSON format
});
}
The problem is, assuming that function even worked. and bby worked I mean return the count of 'User' records in MongoDB, it is not clear how to call it. Ideally, I'd like to call it 50 files toward the surface on the front end.
There is another file, public/modules/users/controllers/authentication.client.controller.js
This file is actually iterated through on the front end, and can be debugged in firefox or chrome.
It has $scope.signup = function() {...} and $scope.signin = function() {...} functions.
I want to prevent the signin page from being displayed, or display an alternate message, depending on the number of User records in MongoDB.
The current problem is that I can't get the count in authentication.client.controller.js because it doesn't know what 'User' is. The other issue is that I don't know how to call the function exports.userCount that I created in the other file, from the front-end, or from authentication.client.controller.js.