I'm trying to query the following object from mongodb
[
{
"id": "6b3a9814c1990a0578988d9e",
"details": {
"buyerId": "5bd450ed0307fa0a3a904376",
"offerId": "1",
"productId": "5b3a9814c1880a0578988d6a",
"productTitle": "Watch",
"amount": 50,
"status": "Open",
}
}
]
I'm using spring-boot-starter-data-mongodb so first, I tried it the standard way.
Here is what's in my repository,
public interface OfferRepository extends MongoRepository<Offer, String> {
List<Offer> findOffersByDetailsBuyerId(String buyerId);
}
I've also tried a custom query,
@Query(value = "{'details.buyerId' : ?0 }")
List<Offer> findOfferByDetails_BuyerId(@Param("buyerId") String buyerId);
Both are coming back with an empty array. But if I hard code the buyerId in the query I get the results I want.
Also, when I debug it, I see the param but with double quotes around it?
screenshot from mongo compass