0

Here is sample code for querying a CosmosDB

Here is the part of the code I am concerned with replicating so I can make queries on my own database.

const cosmos = require("../../lib/");
const CosmosClient = cosmos.CosmosClient;
const config = require("../Shared/config");
const databaseId = config.names.database;
const containerId = config.names.container;

const endpoint = config.connection.endpoint;
const masterKey = config.connection.authKey;

// Establish a new instance of the CosmosClient to be used throughout this demo
const client = new CosmosClient({ endpoint, auth: { masterKey } });

I'm not sure what my endpoint should be in order to query the database. My queries are Read-only (doesn't need to be strictly read only, but for what I'm doing, read-only is all that's needed), but I don't know what is in ../../lib/ that the cosmos variable is set equal to, and I don't know what the endpoint variable should contain (obviously some sort of endpoint, but which one). The ../../lib/ directory doesn't appear to be in the github repo.

1 Answer 1

2

The connection information can be found in the Keys section of the Azure portal.

The endpoint is the value in the URI section.

In case of the CosmosDB emulator, the default URI is https://localhost:8081.

enter image description here

2
  • Do you know how I can get the lib directory? Is it a node package I can import?
    – jaredad7
    Nov 14, 2018 at 16:54
  • 2
    @jaredad7 Yeah you get get that from the Node SDK 2.0 from npm here: npmjs.com/package/@azure/cosmos Nov 14, 2018 at 16:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.