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

Viewed 213

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();
1 Answers
Related