Saurabh Malviya
Saurabh Malviya

Reputation: 17

Couchdb view search by numeric key

I have couchdb setup to have documents like below

   {
    "_id": "id",
    "_rev": "rev",
    "docType": "CLAIM",
    "createDate": 1633074806,
    "customerClaimNumber": "CCN101",
    "claimID": "CLID101"
    }

Requirement is to have claims returned (claim id and customerclaim number) based on the createDate between start of day to end of day. CreateDate is epoch timestamp (an integer)

I have written the below view

function (doc) {
  if(doc.docType =="CLAIM" && doc.claimDate && doc.customerClaimNumber) {
  emit([doc.claimDate], doc.customerClaimNumber, doc.claimID);
  }
}

I am looking at the recommendation to achieve search based on the createDate field (integer)

Upvotes: 0

Views: 51

Answers (1)

Saurabh Malviya
Saurabh Malviya

Reputation: 17

Well eventually i got this done by creating the view as

function (doc) {
  if(doc.docType =="CLAIM" && doc.claimDate && doc.customerClaimNumber) {
  emit(doc.claimDate, {vendorClaimNumber: doc.customerClaimNumber, blockchainClaimID: doc.claimID});
  }
}

and then calling the view

_view/viewname?startkey=1600000212&endkey=1600010212

Upvotes: 1

Related Questions