In our spring Boot application using mongotemplate, I need to write a query to get the results using LIKE
operator. But in mongotemplate just like in SQL, I don't have a direct query which I can use.
I have tried with some of the options like Aggregate
and regex
methods but it didn't work.
In MongoDB tried the same.
db.getCollection('Months').find({"name":/Jan/}).
So in the months
table
, I have to retrieve results that contains 'Jan' letters in the column 'name'. But on running this query suppose I have an entry called 'DecJan' in that Case I am not able to retrieve it.
Query constantQuery = new Query();``
constantQuery.addCriteria(Criteria.where("name").regex("DecJan", "i"));
List<Months> pp = this.mongoTemplate.find(constantQuery, Months.class);
So, the expected is If I have two entries in a table like 'January','DecJan' And in a query, if I pass 'Jan', I need to retrieve both the results using mongotemplate.