Mongo repository query introducing field value from method parameter

18 Views Asked by At

I am trying to look for all the objects inside a Mongodb collection that have the same identification in "jugador" field which is inside the "jugada" object in the collection "jugadas".

For that, I have created a method in the interface that implements mongorepository in spring boot with the following syntax:

public interface JugadaRepository extends MongoRepository<Jugada, String> {
    @Query("{ 'jugador' : {'$oid' : : #{#jugador_id}}")
    List<Jugada> findAllByJugador_id(@Param("jugador_id") String jugador_id);
}

When I substitute the #{#jugador_id}} by any jugadorid string like this:

@Query("{ 'jugador' : {'$oid' : '644aa4b99363b30d6b21fc6f'}}")

... it works without problem, giving all the files "jugadas" that have that string in their "jugador" "_id" fields.

I think the syntax of the interface method query is correct by I don't know enough about mongoDB to be totally sure.

Could you help me in finding out if it is a syntax problem or another issue here?

0

There are 0 best solutions below