0

I am trying to create a view to group on a particular attribute inside an array. However, the below map function is not returning any result.

JSON Document Structure :

{
   "jsontype": "survey_response",
   "jsoninstance": "xyz",
   "jsonlanguage": "en_us",
   "jsonuser": "test@test.com",
   "jsoncontact": "test@mayoclinic.com",
   "pages": [
       {
           q-placeholder": "q1-p1",
           q:localized": "q1-localized-p1",
           q-answer-placeholder": "jawaabu121",
           q-answer-localized": "localized jawaabu1"
       },
       {
           q-placeholder": "q2-p2",
           q:localized": "q2-localized-p2",
           q-answer-placeholder": "jawaabu221",
           q-answer-localized": "localized jawaabu2"
       },
       {
           "q-placeholder": "q3-p3",
           "q:localized": "q3-localized-p3",
           "q-answer-placeholder": "jawaabu313",
           "q-answer-localized": "localized jawaabu3"
       }
   ]
}

Map Function :

function(doc, meta){
emit(doc.jsoninstance,[doc.pages[0].q-placeholder, doc.pages[0].q-localized,doc.pages[0].q-answer-placeholder,q-answer-localized]);
}
davejal
  • 6,009
  • 10
  • 39
  • 82
modek
  • 1

1 Answers1

1

It looks like you made a typo at the end of your emit statement: doc.pages[0].q-answer-placeholder,q-answer-localized.

Instead q-answer-localized should be changed to doc.pages[0].q-answer-localized.

Further to this it seems that you have defined a field as q-localized in your emit statement, but actually according to the sample document that you posted this should actually be q:localized, I assume that this was a mistake in the snippet of the document and not the emit statement, but if not then will also need amending.

I would imagine errors like this would be flagged up in the view engine's map-reduce error log, in future you should check this log so that you will be able to debug errors like this yourself.

The location of the mapreduce_errors log can be found in the Couchbase documentation