MarkLogic node.js api - group by and sort by count

ぃ、小莉子 提交于 2019-12-11 06:34:51

问题


In a relational db you'd have something like "select name, count(1) as c from mytable group by name order by c desc". Basically I want to count how many records contain each name value and get the ones with highest counts first.

Is there a way to do a similar thing in Marklogic using the Node.js API?


回答1:


Something like this should work:

var marklogic = require('marklogic');
var my = require('./my-connection.js');

var db = marklogic.createDatabaseClient(my.connInfo);
var vb = marklogic.valuesBuilder;

db.values.read(
  vb.fromIndexes('name')
    .withOptions({values: ['descending', 'frequency-order']});

The Querying Lexicons and Range Indexes section of the Node.js Application Developer's Guide will provide more detail.



来源:https://stackoverflow.com/questions/40715822/marklogic-node-js-api-group-by-and-sort-by-count

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!