Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Marklogic nodejs Api error

I have the following marklogic rest-api url :

http://marklogicserver:8060/v1/search?format=json&options=optionname&q=question

This url send me results and format them according the optionname. Everything is ok.

Now I need to do the same work with Nodejs API :

I use a querybuilder to do the same thing but my results are never formatted according to optionname.

qb.optionsName = 'optionname';
//qb.search = {q: question};
db.documents.query(
    qb.where(qb.parsedFrom(‘question’))
    ).result( function(results) {
        results.forEach(function(document) {
        console.log(JSON.stringify(document,null,2));
        return document;
    });
    }).catch(function (error){
        console.log(error);
    });

Although I am sure that the optioname is the right one, the system returns the following error message:

[Error: query documents: response with invalid 400 status]
message: 'query documents: response with invalid 400 status',
statusCode: 400,
body:
 { errorResponse:
    { statusCode: 400,
      status: 'Bad Request',
      messageCode: 'REST-INVALIDPARAM',
      message: 'REST-INVALIDPARAM: (err:FOER0000) Invalid parameter: No configured options: optionname' } }
like image 943
PR_MM Avatar asked Jul 25 '26 18:07

PR_MM


2 Answers

You are not passing the querybuilder to the function but a query built by it. Try creating the query and then attaching the optionsName property like this:

var query = qb.where(qb.parsedFrom(‘question’))
query.optionsName = 'optionname';
db.documents
    .query(query)
    .result( function(results) {
        results.forEach(function(document) {
            console.log(JSON.stringify(document,null,2));
            return document;
        });
    })
    .catch(function (error){
        console.log(error);
    });
like image 54
chriskelly Avatar answered Jul 27 '26 11:07

chriskelly


The QueryBuilder defines the query entirely in the client. This approach gives the application complete flexibility for dynamic construction of queries and avoids the housekeeping of maintaining persisted query options.

To use query options persisted on the server, you can instead define a combined query as a JavaScript object and identify the persisted query options in that object:

http://docs.marklogic.com/jsdoc/documents.html#toc14

However, the QueryBuilder alternative is recommended.

Hoping that clarifies,

like image 42
ehennum Avatar answered Jul 27 '26 11:07

ehennum



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!