MongoDB
 sql >> Cơ Sở Dữ Liệu >  >> NoSQL >> MongoDB

Lệnh tổng hợp MongoDB thành mã Java

asList("$modifiedon",1000) phải là asList("$modifiedon","$createdon") theo quy trình hoạt động do bạn cung cấp.

Khi bạn đã thực hiện chỉnh sửa. Có thể thấy rằng vấn đề là bạn đang thêm "then" và "else" vào tài liệu "$ gt" thay vì "if".

Vì vậy, thay vì:

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")
             )
         )
     )
)); 

Bạn nên làm:

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. Redis
  2.   
  3. MongoDB
  4.   
  5. Memcached
  6.   
  7. HBase
  8.   
  9. CouchDB
  1. Các trường truy vấn trong Bộ sưu tập MongoDB.

  2. Truy vấn sau khi điền trong Mongoose

  3. PyMongo max_time_ms

  4. mongodb tìm bằng cách so sánh các giá trị trường

  5. Chọn độ dài chuỗi trong mongodb