Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

203
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda