Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

202
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda