How can I use find select distinct in angularJS then counting it, I'm new to mean-stack and I don't know how to use distinct method.
Here is my table structure with sample data:
donation_no:"3124"
donors_name:"Jeremy Adrian De Vera"
date:"12/26/2018"
time:"8:30"
blood_group:"B"
volume:"2"
branch:"Pasig"
I already tried it using php like this but how can I do this in angular:
$query = "SELECT DISTINCT fruits, COUNT(*) as counter FROM my_table WHERE date_tested BETWEEN '$date_from' AND '$date_to' GROUP BY fruits";
Here is my code for finding the values from my db
api.js
router.get('/blooddonationmanagement', function(req, res) {
Blooddonation.find({},function(err, blooddonations) {
res.json({ success: true, blooddonations: blooddonations });
});
});
blooddonationCtrl.js
angular.module('blooddonationControllers', [])
.controller('blooddonationCtrl', function(Blooddonation,$scope) {
var app = this;
function getBlooddonations() {
Blooddonation.getUsers().then(function(data) {
app.blooddonations = data.data.blooddonations;
});
}
chapters.html
<tr ng-repeat="person in blooddonationmanagement.blooddonations">
<td>{{ person.branch}}</td>
</tr>
How can I count the distinct values then counting it from my db, Im expecting like this:
branch count
Pasig 29
Manila 16
Pasay 19
Just read the docs here: https://docs.mongodb.com/manual/reference/method/db.collection.distinct/
You can use:
db.collection.distinct()