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

  1. SQL to MongoDB Mapping Chart
  2. MongoDB $regex
  3. Spring Data MongoDB : Query Document

上一篇: Spring Data MongoDB : get last modified records (date sorting)
下一篇: jQuery loop over JSON string $.each example
 评论 ( What Do You Think )
名称
邮箱
网址
评论
验证
   
 

 


  • 微信公众号

  • 我的微信

站点声明:

1、一号门博客CMS,由Python, MySQL, Nginx, Wsgi 强力驱动

2、部分文章或者资源来源于互联网, 有时候很难判断是否侵权, 若有侵权, 请联系邮箱:summer@yihaomen.com, 同时欢迎大家注册用户,主动发布无版权争议的 文章/资源.

3、鄂ICP备14001754号-3, 鄂公网安备 42280202422812号