Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
278 views
in Technique[技术] by (71.8m points)

node.js - How can i query data from my azure cosmos db?

I have azure functions written in nodejs. I can't find a way how to get data for example from my created azure cosmos db. I know that there is azure cosmos SDK, but i don't want to use that way.I want to learn to do it through the azure functions because it is possible with them also.

i try do to this:

function.json

{
  "bindings": [
    {
      "authLevel": "anonymous",
      "type": "httpTrigger",
      "direction": "in",
      "name": "req",
      "methods": [
        "get"
      ]
    },
    {
      "type": "http",
      "direction": "out",
      "name": "res"
    },
    {
      "type": "cosmosDB",
      "name": "inputDocument",
      "databaseName": "dbtodos",
      "collectionName": "items",
      "connectionStringSetting": "todos_DOCUMENTDB",
      "partitionKey": "/all",
      "direction": "in"
    }
  ],
  "disabled": false
}

index

module.exports = async function (context, req) {

    context.res = {
            // status: 200, /* Defaults to 200 */
            body: context.bindings.inputDocument
        };
};

after my deploy when i visit the automatically generated url - i can't even open the link.There is not requests coming back.

If i do some basic example where i don't try to pull data from the db then my url is working after deploy.

How can i get the data ?

question from:https://stackoverflow.com/questions/65929525/how-can-i-query-data-from-my-azure-cosmos-db

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

My data in the local.settings.json was wrong. I had azure storage for other table not for the one that i wanted to query... The code works perfectly fine


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...