如何使用db中的值查询mongo db?

时间:2017-01-14 04:25:20

标签: mongodb angular

将angular2与meteor一起使用,并提供以下数据:

#include <stdio.h>
#include <stdlib.h>

int main(void) {
    FILE *fin;
    FILE *fout;
    int i,j;
    int linecount = 0;
    int alphabetCount[26];

    if ((fin = fopen("blocks.in", "r")) == NULL) {
        fprintf(stderr, "Unable to open input file\n");
        exit(EXIT_FAILURE);
    }
    if ((fout = fopen("blocks.out", "w")) == NULL) {
        fprintf(stderr, "Unable to open output file\n");
        exit(EXIT_FAILURE);
    }     

    fscanf(fin," %d",&linecount);

    return 0;
}
  1. 我如何找到具有容量的工人 - available_capacity&gt; 10

  2. 如何找到具有available_capacity&gt; =容量的工人?

1 个答案:

答案 0 :(得分:2)

  1. 我如何找到具有容量的工人 - available_capacity&gt; 10?

    db.collection('workers').find({"capacity": {$gt: 10}}).toArray(function (err, res)    
    {
          if (err) throw err;
          console.log(res);
    });
    
  2. 如何找到具有available_capacity&gt; = capacity?

    的工作人员
    db.collection('workers').aggregate(
    [
      {
       $project:
          {
            _id: 1,
            name: 1,
            capacity:1,
            capacity_available: { $gte: $capacity},
            location: 1
          }
        }
      ]
    );
    
  3. <强>更新

    我刚用完了其他教程。我认为概念将是相同的

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