Created
December 4, 2018 02:24
-
-
Save johncrisostomo/beeb2606603b7ccd019d1eee3a47f1ba to your computer and use it in GitHub Desktop.
connecting and querying cosmodb sql api with nodejs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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