I am trying to query mongodb object and based on the Id ie 456 present in responseBody.
Below is the Java code I have written
String Id = "456";
Query query = new Query();
query.addCriteria(Criteria.where("responseBody.Id").is(Id));
dataList = mongoTemplate.find(query, Data.class);
the above code is working perfectly fine. But because of the change in requirements I need to store the JSON in the responseBody as shown below.
My query is how do I fetch the entire mongoDB object by querying the Id that I have and the object being present in responseBody -> body.
You can simply use JPARespository classes and use the methods like findById or findByName as follows:
@Transactional
@Repository
public interface InstituteRepository extends MongoRepository<Institute, String> {
Institute findByInstituteId(long id);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.