2017-01-25 3 views
-2

erstellen Wie nativen Abfrage von Spring wie dies in MongoDB erstellen:Wie nativen Abfrage von Spring in MongoDB

db.testz.aggregate([{ 
    $match: { 
     fp: { 
      $in: ['100.100', '700.700', '5000.5000', '990000.990000', '777000.777000', 
       '330000.330000', '705000.705000', '350000.350000', '800000.800000', '200000.200000' 
      ] 
     } 
    } 
    }, { 
    $group: { 
     _id: { 
      uuid: '$uuid' 
     }, 
     count: { 
      $sum: 1 
     }, 
     fps: { 
      $push: '$fp' 
     } 
    } 
    }, { 
    $project: { 
     'count': 1, 
     '_id': 0, 
     'uuid': '$_id', 
     'fps': 1 
    } 
    }, { 
    $match: { 
     count: { 
      $gt: 1 
     }, 
     $or: [{ 
      $and: [{ 
       fps: '100.100' 
      }, { 
       fps: '800000.800000' 
      }] 
     }, { 
      $and: [{ 
       fps: '350000.350000' 
      }, { 
       fps: '990000.990000' 
      }] 
     }, { 
      $and: [{ 
       fps: '330000.330000' 
      }, { 
       fps: '5000.5000' 
      }] 
     }, { 
      $and: [{ 
       fps: '705000.705000' 
      }, { 
       fps: '777000.777000' 
      }] 
     }, { 
      $and: [{ 
       fps: '200000.200000' 
      }, { 
       fps: '700.700' 
      }] 
     }] 
    } 
    }, { 
    $group: { 
     _id: { 
      uuid: '$count' 
     }, 
     count: { 
      $sum: 1 
     } 
    } 
    }, { 
    $project: { 
     'count': 1, 
     '_id': 0 
    } 
    }, ]); 

Antwort

0

Sie können so etwas wie unten versuchen. Sie können alle Kriterienwerte einschließen.

Aggregation agg = newAggregation(match(where("fp").in("100.100")), 
       group(fields().and("uuid", "uuid")).count().as("count").push("fp").as("fps"), 
       project(fields("count", "fps").and("uuid", "_id")).andExclude("_id"), 
       match(where("count").gt(1).orOperator(Criteria.where(null).andOperator(Criteria.where("fps").is("100.100"), Criteria.where("fps").is("800000.800000")))), 
       group(fields().and("uuid", "count")).count().as("count"), 
       project(fields("count")).andExclude("_id")); 
Verwandte Themen