2

I am running a couchDB Server with the following map function:

function(doc) {
            if (doc.data.appVersion)  {
                emit([doc.data.appVersion, doc.data.date], doc);
            }
        }

I can easily query for a appVersion or a range of appVersion by using something like this:

Start key: ["1.2.3", 0] End key: ["2.0.0", 10000000000000]

I can also query for a appVersion between two dates:

Start key: ["1.2.3", 1420066800000] End key: ["1.2.3", 1422572400000]

What I can't do is to get all docs regardless of their appVersion but between two dates. This does not work:

Start key: ["0.0.0", 1420066800000] End key: ["9.9.9", 1422572400000]

The query would also include all docs with an appVersion between 0.0.0 and 9.9.9. The date is completely ignored. It is like:

"get all docs with appVersion between 0.0.0 and 9.9.9 OR date between 1420066800000 and 1422572400000".

But want I want is:

"get all docs with appVersion between 0.0.0 and 9.9.9 AND date between 1420066800000 and 1422572400000"

Is there a way to do all make all three query work? Do I have to change the map-function? How? Or do I have to create another map function just for that last kind of query. I'd like to do this with one map-function because there are more properties I'd like to query for.

I am using couchDB with pouchDB on the client side.

4

1 回答 1

3

不幸的是,您确实需要创建一个单独的设计文档,它只发出doc.data.date.

另一个提示:没有必要emit(doc.myKey, doc)。你可以只做emit(doc.myKey)然后使用{include_docs: true}当你query()。这节省了引擎盖下的空间;此博客文章中有详细信息。

于 2015-01-06T20:26:00.827 回答