I am looking to implement aggregation using new lookup feature using pipeline with mongo-scala-driver version 2.30.
MongoQuery aggregation stage I am trying to implement is:
$lookup: {
from: "user",
let: { recipeId: "$_id" },
pipeline:[
{ $match:
{ $expr:
{ $in: ["$$recipeId", "$licenses.recipe"] }
}
}
],
as: "users"
}My current working stage is:
val let = Seq(Variable("recipeId", "$_id"))
val theMatch = Document.apply("""{$match:{$expr:{ $in: ["$$recipeId", "$licenses.recipe"] }}}""").toBsonDocument
val pipeline = Seq(theMatch)
val theLookup = lookup("user", let, pipeline, "users")
//go and run aggregation
val aggr = Seq(
...,
theLookup)
While this does work, I am pretty sure there is better way to use supplied driver library and better implement the Document.apply brute force method I used for, as example, theMatch.
Suggestions appreciated.
I am pretty sure there is better way to use supplied driver library and better implement the Document.apply brute force method I used for, as example, theMatch
Hi Colin,
Currently there’s an open ticket to add support for full aggregation expression language builder JAVA-1949 (MongoDB Scala driver implementation is built upon the MongoDB Java driver). Please feel free to upvote/watch the ticket to receive notifications update on the ticket.
In the meantime, building the $expr via Document/BsonDocument is the recommended way.
Regards,
Wan.