I have an Azure function that queries a CosmosDB for the documents it contains in a collection:
module.exports = function (context, req) {
context.log('JavaScript HTTP trigger function processed a request.');
if (context.bindings) {
var doc = context.bindings.inputDocument;
context.log('Get ready');
context.res = {status: 200, body: doc};
context.log(context.res);
}
else {
context.res = {
status: 400,
body: "Something went wrong"
};
}
context.done();
};
This query brings back everything, where I'm just looking for a specific item to be returned. How can I refactor this to just pull back certain elements? I've tried things like using:
doc.id
Here is the json structure of the sql api configured cosmosdb:
{
"id": "1",
"drink": "gin_and_tonic",
"ingredients": [
"2 ounces gin",
"2 lime wedges",
"3–4 ounces tonic water"
],
"directions": "Add gin to a highball glass filled with ice. Squeeze in
lime wedges to taste, then add them to glass. Add tonic water; stir to
combine.",
"glass": [
"highball",
"hurricane"
],
"image": "https://images.unsplash.com/photo-1523905491727-d82018a34d75?
ixlib=rb-
0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=52731e6d008be93fda7f5af1145eac12&auto=fo
rmat&fit=crop&w=750&q=80"
}
Instead of doc but this does not return anything. I'm also trying to use the @azure/cosmos npm module but it seems a bit overkill and does not seem to use the input defined in the function directly. Any ideas?