Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

documentDB: How to define a callback function in stored procedures when using JavaScript Language Integrated Query?

The documentation states equivalence for the code snippets below. But in the first case I can do operations on the documents collection inside the callback function, while the map function in the latter only works on one document. I do want to group values of the document, which I could do in the callback but not in the map function. Is there a way to accomplish this with the "JavaScript Language Integrated Query"? And how would I set the response body properly?

    __.queryDocuments(__.getSelfLink(),
          "SELECT docs.id, docs.message AS msg " +
          "FROM docs " +
          "WHERE docs.id='X998_Y998'"
        ,
        function(err, docs, options) {
          __.response.setBody(docs);
        });

and

__.chain()
    .filter(function(doc) {
        return doc.id === "X998_Y998";
    })
    .map(function(doc) {
        return {
            id: doc.id,
            msg: doc.message
        };
    })
    .value();
like image 213
juwil Avatar asked Dec 04 '25 14:12

juwil


1 Answers

For those with a similar problem: see the comment above. Put the callback logic in the value function.

like image 57
juwil Avatar answered Dec 07 '25 04:12

juwil



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!