sql >> データベース >  >> NoSQL >> MongoDB

流星でmongodbを反応的に集約する方法

    クライアント側のコレクションがありません。また、このヘルパーに電話する前に登録する必要があります。

    これを試してください

    import { Template } from 'meteor/templating';
    import { ReactiveVar } from 'meteor/reactive-var';
    import './main.html';
    
    var clientReport = new Mongo.Collection('clientReport');
    
    Meteor.subscribe("reportTotals");
    
    Template.header.helpers({
        'tasks': function () {
            console.log("tasks helper called : ");     
            console.log(clientReport.find().fetch());
        },   
    });
    

    また、パイプラインやサーバーコードでの自動実行も必要ありません。これを試してください:

    AtmData = new Mongo.Collection('atmdata');
    
    Meteor.startup(() => {
      // code to run on server at startup
    /*     AtmData.insert({
            bottles_used: 123,
        }); */
    
    });
    
    
    
    Meteor.publish("reportTotals", function() {
    // Remember, ReactiveAggregate doesn't return anything
    
        ReactiveAggregate(this, AtmData, [{
            // assuming our Reports collection have the fields: hours, books    
            $group: {
                '_id': null,
                'bottles_used': {
                // In this case, we're running summation. 
                    $sum: '$bottles_used'
                    // $sum: 1
                }
            }
            }], { clientCollection: "clientReport" });    
    });
    


    1. マングースルートでの約束の使用

    2. MongoDBクエリの最適化

    3. Javaドライバーを使用してMongoDBの配列を更新する

    4. `db.repairDatabase()`なしで削除されたスペースを再利用するにはどうすればよいですか?