Roy Tang Roy Tang - 1 year ago 98
Node.js Question

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

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?

Answer Source

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;
    .withOptions({values: ['descending', 'frequency-order']});

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download