2017-01-14 1 views
0

다음 데이터와 함께, 유성과 angular2 사용 :DB에서 값으로 mongo db를 쿼리하는 방법은 무엇입니까?

{ "_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" } 
  1. 가 어떻게 용량 노동자 찾을 수 있습니까 - AVAILABLE_CAPACITY> 10?

  2. available_capacity> = capacity 인 작업자는 어떻게 구합니까? AVAILABLE_CAPACITY> 10 -

답변

2
  1. 어떻게 용량을 가진 근로자를 찾을 수 있습니까?

    db.collection('workers').find({"capacity": {$gt: 10}}).toArray(function (err, res)  
    { 
         if (err) throw err; 
         console.log(res); 
    }); 
    
  2. available_capacity> = capacity 인 작업자는 어떻게 구합니까?

    db.collection('workers').aggregate(
    [ 
        { 
        $project: 
         { 
         _id: 1, 
         name: 1, 
         capacity:1, 
         capacity_available: { $gte: $capacity}, 
         location: 1 
         } 
        } 
        ] 
    ); 
    

업데이트

난 그냥 다른 튜토리얼을 다했다. 나는 개념이 같은

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에게이 될 것이라 생각합니다. 그냥 짐작한다

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 
       } 
      } 
     ] 
     ); 
     }); 
    }]); 
} 
+0

어떻게 angularjs-meteor에서 db 객체를 얻을 수 있습니까? – Nick

관련 문제