2014-10-31 49 views
1

我試圖在春芒戈層上重新創建此查詢。春芒戈聚合

db.LASTVIEWED_TEST.aggregate([{$match: {'_id' : '12070'}}, 
         {$unwind:"$value"}, 
         {$match:{"value.Dockey":{"$in":["390", "539","626"]}}}, 
         {$group:{_id:"$_id", "value":{$push:"$value"}}} 
         ]) 

我一直在使用各種方法做了一些嘗試,但是我遇到了這裏的例子:

https://github.com/spring-projects/spring-data-mongodb/blob/master/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/aggregation/AggregationTests.java

,並創造了這個:

Aggregation agg = Aggregation.newAggregation(// 
       match(where("entityid").is(entityId)),// 
       unwind("$value"), // 
       match(where("value.Dockey").in(dockeyList)),// 
       group("id").push("$value").as("value")// 
       ); 

然而,這建設者沒有看到識別where,unwind關鍵字等等......而我的編譯器告訴我我的類沒有這些方法。

我需要做什麼才能將值傳遞給newAggregation構建器。

歡呼聲,

回答

1

你需要指定在比賽一Criteria對象,通常所有值都只是字符串表示:

Aggregation agg = newAggregation(
     match(Criteria.where("entityid").is(entityId)), 
     unwind("value"), 
     match(Criteria.where("value.Dockey").in(dockeyList)), 
     group("_id").push("value").as("value") 
    );