title: Couchbase view to filter data between date range
body: <p>I have couchbase documents in following format</p>
  
  <pre><code>{
    "docType": "scheduledJob",
    "orgId": 2,
    "jobs": {
      "1456753078157": {
        "jobName": "Job1",
        "jobId": "910271049",
        "fromTime": 1456752600000,
        "toTime": 1456824600000,
        "key": 1456753141401,
        "status": "pending"
      },
      "1456753141401": {
        "jobName": "Job2",
        "jobId": "558624841",
        "fromTime": 1456752600000,
        "toTime": 1456821000000,
        "key": 1456753141401,
        "status": "pending"
      }
    }
  }
  </code></pre>
  
  <p>Which have jobs scheduled. The jobs can be executed anytime which falls between <strong>fromTime</strong> and <strong>toTime</strong>. My task is to check every hour if there is any job pending for coming hour. Means the whatever the <strong>fromTime</strong> is but <strong>toTime</strong> timestamp should be greater than timestamp of  1 hour after current time. Similarly we should fetch if the <strong>fromTime</strong> is also falls from current timestamp to next hour time stamp.</p>
  
  <p>I am new to couchbase. The view I have created is </p>
  
  <pre><code>function(doc, meta){  
    if( doc.docType &amp;&amp; doc.docType=="scheduledJob"){
      for(var key in  doc.jobs){
        var job = doc.jobs[key]
        if(job.status == "pending") {
      emit(job.fromTime+'_'+job.toTime, job);
        }
      }
  
    }
  
  }
  </code></pre>
  
  <p>I am sending startkey="currentTimestamp_0000000000000" and endkey="0000000000000_currentTime+1hour-timestamp"</p>
  
  <p>Please help me where I am going wrong.</p>