Spring Data MongoDB : like query example
摘要: In SQL, the ‘like’ query is looks like this :
In SQL, the ‘like’ query is looks like this :
select * from tags where tagName like '%apple%'
In MongoDB console, it looks like this :
db.tags.find({"tagName": /apple/})
In Spring data mongodb, it implements with Criteria or BasicQuery :
String tagName = "apple"; Query query = new Query(); query.limit(10); query.addCriteria(Criteria.where("tagName").regex(tagName)); mongoOperation.find(query, Tags.class);
String tagName = "apple"; BasicQuery query = new BasicQuery("{\"tagName\": {$regex : '" + tagName + "'} }"); query.limit(10); mongoOperation.find(query, Tags.class);
References
上一篇:
Spring Data MongoDB : get last modified records (date sorting)
下一篇: jQuery loop over JSON string $.each example
下一篇: jQuery loop over JSON string $.each example