2015-05-06 70 views
0

我試圖通過使用Query DSL與Reactive Mongo Extensions在$in查詢中傳遞多個值。但結果是空的清單。 Follwoing是我的代碼:Reactive Mongo Extensions:在Query中使用`Query DSL`傳遞數值列表

def findUsersByRolesIds(rolesIds: List[BSONObjectID], page: Int, pageSize: Int): Future[List[User]] = { 
    logger.info("findUsersByRolesIds Reactive Repository Method"); 

    userGenericRepo.find($doc("userRoles._id" $in (rolesIds)), $doc("createdOn" -> -1), page, pageSize); 
} 

當我試圖執行上面的代碼,結果是空的。

但是,當我通過,下面的代碼結果是返回。

def findUsersByRolesIds(rolesIds: List[BSONObjectID], page: Int, pageSize: Int): Future[List[User]] = { 
    logger.info("findUsersByRolesIds Reactive Repository Method"); 

    userGenericRepo.find($doc("userRoles._id" $in (BSONObjectID.apply("5548b098b964e7039852ff58"))), $doc("createdOn" -> -1), page, pageSize); 
} 

的主要問題是,我有多個值,所以這就是爲什麼我創建列表但這裏的列表是行不通的。如何通過reactive mongo extenstionsQuery DSL查詢此查詢。

+0

嘗試'val query = $ doc(...); println(s「query = $ {BDONDocument pretty query}」)'然後從MongoDB CLI手動執行查詢以檢查數據是否存在。 – cchantep

+0

@cchantep這是查詢的輸出'query = {「userRoles._id」:{「$ in」:[[{「$ oid」:「5548b098b964e7039852ff58」}]]}}'。仍然沒有數據返回。 –

回答

2

$ in期望可變參數,即val dsl: BSONDocument = "age" $in (1, 2, 3)。所以你不能直接向它傳遞一個集合。嘗試使用這個"age" $in (rolesIds: _*)

+0

謝謝@fcs。這真的對我有幫助。我認爲這也需要包括'Query DSL'文檔。 –

+0

@HarmeetSinghTaara你介意發送一個PR嗎? – fcs

+0

什麼是公關,我不明白? –