0

私はMongoDBとCasbahの初心者です。誰かが私を助けてくれるのではないかと思っています。Scala、casbah集約クエリ

私は、次のMongoDBのクエリを持って働き、

db.getCollection('holidayRequests').aggregate 
(
    [ 
    { $match: { $and: [ { email: "[email protected]" } , { status: "APPROVED" } ] }}, 
     { 
      $group: 
     { 
      _id: { email: "$email" }, 
      totalAmount: { $sum: "$daysTaken" } 
     } 
    } 
    ] 
); 

私は、クエリにこれを変換するにはどうすればよいカスバドライバが理解しますか?そのような

答えて

0

何か:

import com.mongodb.casbah.commons.MongoDBObject 
import com.mongodb.casbah.commons.MongoDBList 
import com.mongodb.casbah.MongoClient 

object testCasbah { 

    val mongoClient = MongoClient() /* database connections parameters */ 
    val db = mongoClient("databaseName") 

    val email = MongoDBObject("email" -> "[email protected]") 
    val status = MongoDBObject("status" -> "APPROVED") 

    val and = MongoDBObject("$and" -> List(email, status)) 

    val pipeline = MongoDBList(MongoDBObject("$match" -> and)) ++ 
       MongoDBList(MongoDBObject("$group" -> 
        MongoDBObject("_id" -> MongoDBObject("email" -> "$email"), 
            "totalAmount" -> MongoDBObject("$sum" -> "$daysTaken")))) 

    db.command(MongoDBObject("aggregate" -> "holidayRequests", "pipeline" -> pipeline))        

} 

が動作するはずです。

関連する問題