score:-1

Here is way to do aggregation after using filter(field i > 0) and project (convert input as ITimes10 value after multiplying i with 10) pipeline stages.

import org.mongodb.scala.model.Aggregates._

collection.aggregate(Seq(filter(gt("i", 0)),
  project(Document("""{ITimes10: {$multiply: ["$i", 10]}}""")))
).printResults()

For more details visit this github links mongo-scala-quick-tour and mongo-scala-aggregation

score:0

I have an array locations and I want to keep in array object with field location where location string ends with "Deutschland"

In shell it look:

db.someCollection.aggregate([{
    $project: {
        locations: {
            $filter: {
                input: "$locations",
                as: "item",
                cond: {
                    "$regexMatch": {
                        "input": "$$item.location",
                        "regex": "Deutschland$"
                    }
                }
            }
        }
    }
}])

in Scala:

collection("someCollection").
      aggregate[TypeOfObjectInArray](Seq(
    project(fields(
      computed("locations", Document ("$filter" ->
        Document("input" -> "$locations", "cond" ->
          Document("$regexMatch" -> Document("input" -> "$$this.location", "regex" -> "Deutschland$")))))
      )
    )
  )
)

Related Query

More Query from same tag