Marklogic | NodeJS API-查询字段的属性 [英] Marklogic|NodeJS API - Query on attribute of a field

查看:73
本文介绍了Marklogic | NodeJS API-查询字段的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类似json的结构

I have a json structure something like

{
   foo:"bar",
   keyPhrases:[
      {key: "random thing", value: 5},
      {key: "another random", value: 3}
   ]
}

如何在keyPhrases.key上进行单词查询? 我尝试过

How can i do a word query on keyPhrases.key ? I tried

qb.word('keyPhrases.key', 'random')

qb.word(qb.property('keyPhrases.key'), 'random')

,它不起作用.有任何想法吗?我知道QBE可以做到这一点,但是对于Marklogic NodeJS API,您无法指定集合,而我需要这样做.

and it does not work. Any ideas? I know this is possible with a QBE but for the Marklogic NodeJS API you can`t specify a collection, and I need to.

推荐答案

您需要 qb. scope().

var ml = require('marklogic');
var conn = require('./config.js').connection;
var db = ml.createDatabaseClient(conn);
var qb = ml.queryBuilder;

db.documents.query(
  qb.where(
    qb.collection('test'),
    qb.scope(qb.property('keyPhrases'), qb.word('key', 'random'))
  )
  .withOptions({metrics: true})
).result()
.then(function(docs) {
  console.log('This search found: ' + JSON.stringify(docs[1]));
})
.catch(function(error) {
  console.log('something went wrong: ' + error);
});

或者,您可以构建基于路径的字段并对此进行查询.

Alternatively, you could build a path-based field and query on that.

这篇关于Marklogic | NodeJS API-查询字段的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆