简体   繁体   English

MarkLogic Node.js。 如何在结果中指定返回属性

[英]MarkLogic Node.js. How to specify return properties in result

How can I specify returned fields in my query so that I can avoid large data in my response.如何在查询中指定返回的字段,以便在响应中避免使用大数据。 For example I have a json like this and I want only summary in response:例如,我有一个这样的 json,我只想要摘要作为回应:

{
   foo:"bar",
   summary:"my summary",
   other:[
      {key: "random thing", value: 5},
      {key: "another random", value: 3}
   ]
}
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')   
  )
  .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);
});

Here are a couple of options:这里有几个选项:

  • Install a transform and transform the documents on the server;安装转换并转换服务器上的文档; see:看:

https://docs.marklogic.com/guide/node-dev/search#id_79910 https://docs.marklogic.com/guide/node-dev/search#id_79910

  • Specify paths to extract from the documents:指定从文档中提取的路径:

https://docs.marklogic.com/guide/node-dev/search#id_17648 https://docs.marklogic.com/guide/node-dev/search#id_17648

Hoping that helps,希望有所帮助,

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM