mongodbmongo-java-driver

$elemMatch equivalient for nested array as com.mongodb.client.model.Filters.elemMatch


i wrote the following filter in the mongodb console

"outers":{"$elemMatch":{"$elemMatch":{y:{$gt : 48.99}}}}

what would be the bson equivalent? i got this:

elemMatch("outers", elemMatch("y", gt("y", 48.99)))

but it feels wrong, because of the duplicate y-variable


Solution

  • I think this should work:

    Filters.elemMatch("outers", Filters.lt("y", 48.99))