I write the criteria query like this
query.addCriteria(Criteria.where("_id").is(id));
but the result is {"_id":123456789123450}
which is not searching result. What I need to change to search the result using the criteria query on _id
?
There are two ways to do this
Query query = new Query(Criteria.where("id").is(new ObjectId(<id value>)));
Or Spring data MongoDB's findById
org.springframework.data.repository.CrudRepository.findById(String id);
https://docs.spring.io/spring-data/commons/docs/current/api/org/springframework/data/repository/CrudRepository.html#findById-ID-
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With