0

the response of my map function is:

key:

[ 1525132800000, 1525152600000 ]

value:

{
  "propertyId": "DAWN",
  "startDate": "2018-05-01",
  "endDate": "2018-05-04",
  "verificationStatusCode": "ICMO"
}

In Key, there are two date fields which are used for filtering out the required result set. I want to get the counts of docs after grouping them on all the fields available in the response of map function. I am not able to write reduce function for this. Any suggestion on how it can be done? The response from the reduce function I want is:

{
  "propertyId": "DAWN",
  "startDate": "2018-05-01",
  "endDate": "2018-05-04",
  "verificationStatusCode": "ICMO", 
 "count":54
}
Cœur
  • 37,241
  • 25
  • 195
  • 267
  • What are given array(s) and what is the expected output? – Eddie Apr 02 '18 at 08:47
  • @Eddie, this is the N1QL query that I am trying to convert into map reduce. Hope it helps. `Select propertyId, startDate, endDate, verificationStatusCode, Count(*) From default Where type = "DocumentStatus" and lastModifiedDocDateEPOCH >= 1521718200000 and startDateEpoch between 1522627200000 and 1523232000000 Group by propertyId, startDate, endDate, verificationStatusCode ;` – Krishan Jangid Apr 02 '18 at 13:17
  • This is the document structure: `{ "propertyId": "DAWN", "startDate": "2018-05-01", "endDate": "2018-05-04", "startDateEpoch":1525132800000, "endDateEpoch": 1525392000000, "lastModifiedDocDateEPOCH": 1521718200000, "verificationStatusCode": "ICMO" }` – Krishan Jangid Apr 02 '18 at 13:22

1 Answers1

0

I would suggest you to use a long combination of keys for grouping and filtering, it would look like this:

emit([propertyId, startDate, endDate, verificationStatusCode, startDateEpoch, lastModifiedDocDateEPOCH])

and the key ranges should look like this

query.range(
    [propertyId, startDate, endDate, verificationStatusCode, "1522627200000"], 
    [propertyId, startDate, endDate, verificationStatusCode, "1523232000000", {}])
Chinh Nguyen
  • 583
  • 1
  • 7
  • 14