chinuy
chinuy

Reputation: 165

couchDB startkeys from specific date

I have a couchDB view format like:

"map": "function(doc) { emit([doc.uid, doc.timestamp], doc._id); }"

And I want to query by the uid with timestamp. (timestamp is epoch format)

_http://url_to_CouchDB/DB/_design/query/_view/view?startkey=[uid1,1405485278284]&endkey=[uid1,{}]

However, the timestamp I put in the startkey seems being ignore and the view output is the same without specifying timestamp.

What I want is to query the view by before the timestamp, so that I don't have to return all doc_id at once.

p.s. uid here is the user id I want to query to. The function here is to find all the post of a user by the time stamp.

Thanks

Upvotes: 1

Views: 541

Answers (1)

SingleNegationElimination
SingleNegationElimination

Reputation: 156188

What is the selectivity like for doc.uid; is it different for every document? If so, then your view will be generally insensitive to the timestamp. Consider

function(doc) {
    emit([doc.timestamp], null);
}

note also that you don't need to include the doc._id explicitly in the mapped results, it's always present in the result for un-reduced queries.

Upvotes: 1

Related Questions