Date Filtering v 2.5.1

I’m using version 2.5.1 and I cannot seem to get date filtering to work.

Here is my view.

function (doc, meta) {
  if(doc.Type == "SfdcAccount") {
    emit(dateToArray(doc.LastModifiedDate), doc.Id);    


I see all of my “Account” records in the result set no matter what I changed startKey, endKey, and descending to. I can even completely dump endKey and I still get all the results.

Is this busted in 2.5.1 or am I using an outdated approach?



What do you mean when you say you see all of the “Account” records? What’s the key in the logical ‘row’ for that?

Also, note that dateToArray() would give you something with more than a single element in the array. If you’re querying for one element, then you’ll typically have group_level or reduce in the query argument.

Sorry if I’m not quite getting it. Would be good to see what some sample docs look like.

Hi ingenthr!

Here’s a sample doc.

  "Id": "001asdfdsf6dsfG",
  "AccountMainContactName": "Corey",
  "LastModifiedDate": "2014-09-22T14:21:31-05:00",
  "Type": "Account"

For this view, I simply wanted to get a list of "Id"s for records with LastModifiedDate in a range. Perhaps I should include Id in the key?

I can make the Keys unique by incorporating my unique ids.

function (doc, meta) {
  if(doc.Type == "SfdcAccount") {
    emit([dateToArray(doc.LastModifiedDate), doc.Id], doc.Id);    

I’ve tried this and attempted to use some partial matching like so:


…but, I think it doesn’t like my key because I still retrieve the full result set rather than only the records with LastModifiedDate since 10/16/2014.


I have started to get some good results since I changed the view to include the Id.

http://localhost:8092/sfdc-cache/_design/accounts/_view/accounts_by_source_and_lastmodifieddate?descending=false&startkey=[[2014,9,10,0,0,0]] is filtering the data down now to matches since 9/10/2014.

I also got a similar query to work in the c# api on this view.

        var lastTimeChangesSentOut = new DateTime(2014, 10, 16);
        var accounts = couchClient.GetView("accounts", "accounts_by_source_and_lastmodifieddate")
                                  .StartKey<object[]>(new object[] { new object[] { lastTimeChangesSentOut.Year, lastTimeChangesSentOut.Month, lastTimeChangesSentOut.Day } })