How to write wildcard search query in couchdb where name like 'a%'

三世轮回 提交于 2019-12-22 09:29:48

问题


How can I write wildcard search in couchdb? I want to write query same as 'LIKE %' in sql.please help me for this.

 {
"name":"arun",
"surname":"mr"
}

 {
"name":"balu",
"surname":"tp"
}

I need to list all names that start with 'a'.

Thanks..


回答1:


In couchdb you can query over string ranges.

First you need to have a view that emits all the names as keys

function(doc){
  if(doc.name)
  emit(doc.name,null);
}

Then you can query it with

http://localhost:5984/your-db-name/_design/your-ddoc-name/_view/your-view-name?startkey="a"&endkey="a\ufff0" which will give you all the names starting with a.

'\uff0' is just a high value unicode character, not a specific character that will perform magic tricks in couchdb.



来源:https://stackoverflow.com/questions/24909317/how-to-write-wildcard-search-query-in-couchdb-where-name-like-a

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!