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

JavaコードへのMongoDBAggregationコマンド

    asList("$modifiedon",1000) asList("$modifiedon","$createdon")である必要があります あなたが提供する作業パイプラインに従って。

    編集を行ったように。問題は、「if」ではなく「$gt」ドキュメントに「then」と「else」を追加していることであることがわかります。

    代わりに:

    AggregateIterable<Document> iterable = collection.aggregate(
    
    asList( new Document("$redact", 
             new Document("$cond", 
                 new Document("if", 
                     new Document("$gt",
                          asList(new Document("$subtract",
                              asList("$modifiedon", "$createdon")
                          ),1000 * 60 * 60 * 24)
                  ).append("then", "$$KEEP")
                   .append("else", "$$PRUNE")
                 )
             )
         )
    )); 
    

    あなたがすべきこと:

    AggregateIterable<Document> iterable = collection.aggregate(
    
    asList( new Document("$redact", 
             new Document("$cond", 
                 new Document("if", 
                     new Document("$gt",
                          asList(new Document("$subtract",
                              asList("$modifiedon", "$createdon")
                          ),1000 * 60 * 60 * 24)
                  )
                 ).append("then", "$$KEEP")
                   .append("else", "$$PRUNE")
             )
         )
    ));
    



    1. クラウド環境のSSDでのApacheHBaseとApacheCassandraのベンチマーク

    2. MongoDBでupdate()とsave()のパフォーマンスを向上させる方法は?

    3. いつ実際に使用するのか、Redis lua?

    4. クラスターフェイルオーバー