Skip to content

Instantly share code, notes, and snippets.

@johncrisostomo
Created December 4, 2018 02:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johncrisostomo/beeb2606603b7ccd019d1eee3a47f1ba to your computer and use it in GitHub Desktop.
Save johncrisostomo/beeb2606603b7ccd019d1eee3a47f1ba to your computer and use it in GitHub Desktop.
connecting and querying cosmodb sql api with nodejs
const CosmosClient = require('@azure/cosmos').CosmosClient;
const cosmosClient = new CosmosClient({
endpoint: '', // connection url
auth: {
masterKey:
'' // master key
}
});
const databaseDefinition = { id: '' }; // database name / id
const collectionDefinition = { id: '' }; // collection name / id
const test = async () => {
try {
const dbResponse = await cosmosClient.databases.createIfNotExists(
databaseDefinition
);
const database = dbResponse.database;
const coResponse = await database.containers.createIfNotExists(
collectionDefinition
);
const container = coResponse.container;
const { result: results } = await container.items
.query('', {
enableCrossPartitionQuery: true
})
.toArray();
console.log(results);
} catch (err) {
console.log(err);
}
};
test();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment