using angular2 with meteor, with the following data:
{ "_id" : "DxEraKtfYavoukdCK", "name" : "Aaron", "capacity" : 20, "available_capacity" : 15, "location" : "1" }
{ "_id" : "yMhEggaGmS7iio9P4", "name" : "Benard", "capacity" : 20, "available_capacity" : 20, "location" : "2" }
{ "_id" : "TTD2wedGYWaLctJHt", "name" : "Candy", "capacity" : 50, "available_capacity" : 15, "location" : "3" }
how do i find workers with capacity - available_capacity > 10?
how do i find workers with available_capacity >= capacity?
how do i find workers with capacity - available_capacity > 10?
db.collection('workers').find({"capacity": {$gt: 10}}).toArray(function (err, res) { if (err) throw err; console.log(res); });
how do i find workers with available_capacity >= capacity?
db.collection('workers').aggregate( [ { $project: { _id: 1, name: 1, capacity:1, capacity_available: { $gte: $capacity}, location: 1 } } ] );
Update
I just ran out other tutorials. I think the concept will be the same
Q1
Workers = new Mongo.Collection('workers');
if (Meteor.isClient) {
// This code only runs on the client
angular.module('simple-todos',['angular-meteor']);
angular.module('simple-todos').controller('TodosListCtrl', ['$scope', '$meteor',
function ($scope, $meteor) {
$scope.findWorkers = $meteor.collection( function() {
return Workers.find({"capacity": {$gt: 10}});
});
}]);
}
Q2
I don't know aggregate gonna working here. Just guess
Workers = new Mongo.Collection('workers');
if (Meteor.isClient) {
// This code only runs on the client
angular.module('simple-todos',['angular-meteor']);
angular.module('simple-todos').controller('TodosListCtrl', ['$scope', '$meteor',
function ($scope, $meteor) {
$scope.findWorkers = $meteor.collection( function() {
return Workers.aggregate(
[
{
$project:
{
_id: 1,
name: 1,
capacity:1,
capacity_available: { $gte: $capacity},
location: 1
}
}
]
);
});
}]);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.