Small promise based wrapper around documentdb package for interacting with Azure Cosmos Document Databases
npm install @hypertext.solutions/simple-documentdb-clientThis project provides a small promise based wrapper around the documentdb package. The goal is to provide an simpler and promise based API for working with Azure Cosmos DB Document Databases.
npm install @hypertext.solutions/simple-documentdb-client --save
`Create the client
`javascript
const key = "your-key";
const endpoint = "https://your-server.documents.azure.com:443";
const db = "your-database";
const collection = "your-collection";
const clientFactory = require("@hypertext.solutions/simple-documentdb-client");let client = clientFactory(endpoint, key, db, collection);
`Query
Used for querying documents
`javascript
client.query("SELECT * FROM ROOT")
.then(results => console.log("All the documents", results))
.catch(console.err);
`Upsert (create/update)
Used for creating or updating a document
`javascript
let document = { message: "I'm a new document" };client.upsert(document)
.then(result => console.log("The new document", result))
.catch(console.err);
`Delete
Used for deleting documents
`javascript
client.query("SELECT * FROM ROOT")
.then(results => {
console.log("Deleting all documents");
results.forEach(doc => {
client.delete(doc)
.then(deleted => console.log(Deleted ${deleted._self}))
.catch(console.err);
});
})
.catch(console.err);
``