2012-11-14 53 views
0

MongoDB Documentation我們已經得到了下面的例子:春數據MongoDB的索引查詢的子文件

db.factories.insert({ name: "xyz", metro: { city: "New York", state: "NY" } }); 
db.factories.ensureIndex({ metro : 1 }); 
// this query can use the above index: 
db.factories.find({ metro: { city: "New York", state: "NY" } }); 

目前我正在尋找一個解決方案春季數據archieve此查詢。我的第一個方法是

Query.query(Criteria.where("metro") 
    .andOperator(Criteria.where("city").is("New York") 
    .and("state").is("NY"))) 

但這會導致下面的查詢

{ "metro" : { } , "$and" : [ { "city" : "New York" , "state" : "NY"}]} 

回答

0

最後我通過擺弄周圍找到了解決辦法:

Query.query(Criteria.where("metro").is(
    Query.query(
     Criteria.where("city").is("New York") 
     .and("state").is("NY")).getQueryObject() 
    ) 
) 
// results in { metro: { city: "New York", state: "NY" } } 

希望這是做的正確方法...