开发者

CouchDB key always matches

I'm looking to query my CouchDB in such a way that some of the fields in a document can be wil开发者_如何转开发dcards that match any key request.

Example:

function(doc) {
  emit(doc.some_field, doc);
}

?key=100 would match both the document with some_field of 100 and of some_field value like *.

Is this possible? Is there a hack to do that?


As per the CouchDB documentation you can do:

?startkey="key"&endkey="key\ufff0"

to match key*.


From Couchdb wiki:

CouchDB actually stores the [key,docid] pair as the key in the btree. This means that:

  • you always know which document the key and value came from (it's exposed as the 'id' field in the view result)
  • view rows with equal keys sort by increasing docid.

So I don't think that wildcard fields used as a part of a key are possible because they are sorted. Suppose they are possible. Then if you try to query a key range from a view, rows with a wildcard will be returned with any key range. That means that they are everywhere. But that's impossible because they are sorted. That is a row with a wildcard is placed between a pair of other rows one of which has a greater key and the other a smaller one.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜