ClassNotFoundException
ClassNotFoundException

Reputation: 409

Query ReactiveMongo by a nested field

I have an object in a collection:

{ "id" : "123", "option" : { "key" : "one" , "value" : "1" }}

I can find the object like this:

collection.find(BSONDocument("option" -> BSONDocument("key" -> "one", "value" -> "1")))

However, what I need is to be able to find the object only by the value ('1' in the example), without having to specify the whole child document.

Is there any way to do it in Reactivemongo?

Upvotes: 2

Views: 345

Answers (1)

TechWisdom
TechWisdom

Reputation: 4295

To query by fields in an embedded or a nested document, use dot notation:

collection.find(BSONDocument("option.value" -> "1"))

Upvotes: 2

Related Questions