According to the documentation, the code snippets below are considered equivalent. However, I have observed that in the first case, I am able to perform operations on multiple documents within the callback function, whereas the map function in the latter snippet only operates on a single document at a time. My goal is to group values of the document, which I can achieve in the callback but not with the map function. Is there a way to accomplish this using the "JavaScript Language Integrated Query"? And how should I properly set the response body?
__.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();