2 years ago
#86664
Koala
MongoDB JSON based query methods
public interface SomethingRepository extends MongoRepository<Something, String> {
@Query("{ '_id' : ?0 }")
Something findByNestedObjectId(String _id);
}
I am using the SpringFramework to make queries to my MongoDB and I know that such a query as above is possible, but what about such a query as below?:
public interface SomethingeRepository extends MongoRepository<Something, String> {
@Query("{ 'employee' : { '_id' : ?0 }}")
Something findByEmployeeObjectId(String _id);
}
The searched _id is a field of an Employee Object inside a Mongo Document. On this site I found that:
String parameter values are escaped during the binding process, which means that it is not possible to add MongoDB specific operators through the argument.
Does that mean it is not possible to power such a query as in the second code example?
Here the Mongo Document
@Document(collection = "something")
public class Something {
@Id
private String _id;
@Field
private Employee employee
}
java
spring
mongodb
mongorepository
0 Answers
Your Answer