Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

201
Views
How to access array of objects in Marklogic jsearch mapper function

I have a JSON document in format below in a collection:

{
 "id":{
  "idValue":[
   {"value1": ["a"],
    "value2":["b"]
   },
   {"value1": ["a"],
    "value2":["c"]
    }
  ]
 }
}

I need to fetch the JSON documents having "value1"=="a" and "value2"=="b" and return only that instance.

I have used jsearch in my code as below

const jsearch = require('/MarkLogic/jsearch.sjs');
var prodct = jsearch.collections(["idCollection"]);
function mapper(result) {
 return {
  value1: result.document.id["idValue"],
  value2: result.document.id["idValue"]
 };
}
var output=
 prodct.documents()
.where(cts.andQuery([cts.jsonPropertyWordQuery("value1","a"),cts.jsonPropertyWordQuery("value2","b")]))
.slice(0,10)
.map(mapper)
.result();
output.results

How to access the array of values in mapper function ?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You could reference the array items by their index. When you want the value of the node, use .valueOf():

function mapper(result) {
 const idValue = result.document.id.idValue[0]
 return {
  value1: idValue.value1[0].valueOf(),
  value2: idValue.value2[0].valueOf()
 };
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!