How to use documentdb - 10 common examples

To help you get started, we’ve selected a few documentdb examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cloudlibz / clocal-azure / example / azure-cosmosdb / app.js View on Github external
let app = express();

// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');

// uncomment after placing your favicon in /public
//app.use(favicon(__dirname + '/public/favicon.ico'));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

// Todo App
let docDbClient = new DocumentDBClient(config.host, {
    masterKey: config.authKey
});
let taskDao = new TaskDao(docDbClient, config.databaseId, config.collectionId);
let taskList = new TaskList(taskDao);
taskDao.init(function(err) { if(err) throw err; });

app.get('/', taskList.showTasks.bind(taskList));
app.post('/addtask', taskList.addTask.bind(taskList));
app.post('/completetask', taskList.completeTask.bind(taskList));

// catch 404 and forward to error handler
app.use(function(req, res, next) {
    let err = new Error('Not Found');
    err.status = 404;
    next(err);
});
github Azure / azure-sdk-for-js / tutorial / todo / app.js View on Github external
var app = express();

// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');

// uncomment after placing your favicon in /public
//app.use(favicon(__dirname + '/public/favicon.ico'));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

// Todo App
var docDbClient = new DocumentDBClient(config.host, {
    masterKey: config.authKey
});
var taskDao = new TaskDao(docDbClient, config.databaseId, config.collectionId);
var taskList = new TaskList(taskDao);
taskDao.init();

app.get('/', taskList.showTasks.bind(taskList));
app.post('/addtask', taskList.addTask.bind(taskList));
app.post('/completetask', taskList.completeTask.bind(taskList));

// catch 404 and forward to error handler
app.use(function(req, res, next) {
    var err = new Error('Not Found');
    err.status = 404;
    next(err);
});
github Azure-Samples / documentdb-node-todo-app / src / app.js View on Github external
var app = express();

// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');

// uncomment after placing your favicon in /public
//app.use(favicon(__dirname + '/public/favicon.ico'));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

// Todo App
var docDbClient = new DocumentDBClient(config.host, {
    masterKey: config.authKey
});
var taskDao = new TaskDao(docDbClient, config.databaseId, config.collectionId);
var taskList = new TaskList(taskDao);
taskDao.init(function(err) { if(err) throw err; });

app.get('/', taskList.showTasks.bind(taskList));
app.post('/addtask', taskList.addTask.bind(taskList));
app.post('/completetask', taskList.completeTask.bind(taskList));

// catch 404 and forward to error handler
app.use(function(req, res, next) {
    var err = new Error('Not Found');
    err.status = 404;
    next(err);
});
github microsoft / botbuilder-js / libraries / botbuilder-azure / lib / cosmosDbStorage.js View on Github external
constructor(settings, connectionPolicyConfigurator = null) {
        if (!settings) {
            throw new Error('The settings parameter is required.');
        }
        this.settings = Object.assign({}, settings);
        // Invoke collectionPolicy delegate to further customize settings
        let policy = new documentdb_1.DocumentBase.ConnectionPolicy();
        if (connectionPolicyConfigurator && typeof connectionPolicyConfigurator === 'function') {
            connectionPolicyConfigurator(policy);
        }
        this.client = new documentdb_1.DocumentClient(settings.serviceEndpoint, { masterKey: settings.authKey }, policy);
    }
    read(keys) {
github microsoft / botbuilder-js / libraries / botbuilder-azure / src / cosmosDbStorage.ts View on Github external
throw new Error('The settings dataBase ID is required.');
        }

        if (!settings.collectionId || settings.collectionId.trim() === '') {
            throw new Error('The settings collection ID is required.');
        }

        this.settings = {...settings};

        // Invoke collectionPolicy delegate to further customize settings
        const policy: ConnectionPolicy = new DocumentBase.ConnectionPolicy();
        if (connectionPolicyConfigurator && typeof connectionPolicyConfigurator === 'function') {
            connectionPolicyConfigurator(policy);
        }

        this.client = new DocumentClient(settings.serviceEndpoint, { masterKey: settings.authKey }, policy);
        this.databaseCreationRequestOption = settings.databaseCreationRequestOptions;
        this.documentCollectionCreationRequestOption = settings.documentCollectionRequestOptions;
    }
github Azure / azure-sdk-for-js / core_sdk / tutorial / todo / routes / index.js View on Github external
// import the modules we will use
var DocumentDBClient = require('documentdb').DocumentClient;
var nconf = require('nconf');

// tell nconf which config file to use
nconf.env();
nconf.file({ file: 'config.json' });

// create some global variables which we will use later to hold instances of the DocumentDBClient, Database and Collection
var host = nconf.get("HOST");
var authKey = nconf.get("AUTH_KEY");
var databaseId = nconf.get("DATABASE");
var collectionId = nconf.get("COLLECTION");
// create an instance of the DocumentDB client
var client = new DocumentDBClient(host, { masterKey: authKey });

exports.index = function (req, res) {
    // before we can query for Items in the document store, we need to ensure we 
    // have a database with a collection then use the collection to read the documents
    readOrCreateDatabase(function (database) {
        readOrCreateCollection(database, function (collection) {
            listItems(collection, function (items) {
                res.render('index', { title: 'My ToDo List', tasks: items });
            });
        });
    });
};

exports.createOrUpdateItem = function (req, res) {
    //first have to set the database & collection context so that we have the self links   
    readOrCreateDatabase(function (database) {
github Azure / azure-sdk-for-js / samples / DocumentManagement / app.js View on Github external
, async = require('async')
  , databaseId = config.names.database
  , collectionId = config.names.collection
  , dbLink
  , collLink;

var host = config.connection.endpoint;
var masterKey = config.connection.authKey;

var documentDefinitions = function () {
    var data = fs.readFileSync('../Shared/Data/Families.json');   
    return JSON.parse(data).Families;
};

// Establish a new instance of the DocumentDBClient to be used throughout this demo
var client = new DocumentDBClient( host, { masterKey: masterKey });

//NOTE: 
//when using the new IDBased Routing URIs, instead of the _self, as we 're doing in this sample
//ensure that the URI does not end with a trailing '/' character
//so dbs/databaseId instead of dbs/databaseId/

//-------------------------------------------------------------------------------------------------------
// This demo performs a few steps
// 1. createDocuments   - Insert some documents in to collection
// 2. listDocuments     - Read the document feed for a collection
// 3. readDocument      
// 3.1                  - Read a single document by its id
// 3.2                  - Use ETag and AccessCondition to only return a document if ETag does not match
// 4. queryDocuments    - Query for documents by some property
// 5. replaceDocument   
// 5.1                  - Update some properties and replace the document
github teamdigitale / io-functions / lib / admin_api.ts View on Github external
secureExpressApp(app);

// Setup DocumentDB

const cosmosDbUri = getRequiredStringEnv("CUSTOMCONNSTR_COSMOSDB_URI");
const cosmosDbKey = getRequiredStringEnv("CUSTOMCONNSTR_COSMOSDB_KEY");
const cosmosDbName = getRequiredStringEnv("COSMOSDB_NAME");

const documentDbDatabaseUrl = documentDbUtils.getDatabaseUri(cosmosDbName);

const servicesCollectionUrl = documentDbUtils.getCollectionUri(
  documentDbDatabaseUrl,
  "services"
);

const documentClient = new DocumentDBClient(cosmosDbUri, {
  masterKey: cosmosDbKey
});

const serviceModel = new ServiceModel(documentClient, servicesCollectionUrl);

// Setup handlers

const debugHandler = GetDebug(serviceModel);
app.get("/adm/debug", debugHandler);
app.post("/adm/debug", debugHandler);

app.get("/adm/services/:serviceid", GetService(serviceModel));
app.post("/adm/services", CreateService(serviceModel));
app.put("/adm/services/:serviceid", UpdateService(serviceModel));

const azureFunctionHandler = createAzureFunctionHandler(app);
github teamdigitale / io-functions / lib / compute_visible_services.ts View on Github external
}

// Whether we're in a production environment
const isProduction = process.env.NODE_ENV === "production";

const cosmosDbUri = getRequiredStringEnv("CUSTOMCONNSTR_COSMOSDB_URI");
const cosmosDbKey = getRequiredStringEnv("CUSTOMCONNSTR_COSMOSDB_KEY");
const cosmosDbName = getRequiredStringEnv("COSMOSDB_NAME");

const documentDbDatabaseUrl = documentDbUtils.getDatabaseUri(cosmosDbName);

const servicesCollectionUrl = documentDbUtils.getCollectionUri(
  documentDbDatabaseUrl,
  SERVICE_COLLECTION_NAME
);
const documentClient = new DocumentClient(cosmosDbUri, {
  masterKey: cosmosDbKey
});

const serviceModel = new ServiceModel(documentClient, servicesCollectionUrl);

function reduceServicesToVisibleServices(
  visibleServicesObj: StrMap,
  service: RetrievedService
): StrMap {
  // we use an in-memory object (map)
  // to temporary store visible services
  const maybeVisibleService = lookup(service.serviceId, visibleServicesObj);
  if (
    !service.isVisible &&
    isSome(maybeVisibleService) &&
    service.version > maybeVisibleService.value.version
github teamdigitale / io-functions / lib / webhook_queue_handler.ts View on Github external
documentDbDatabaseUrl,
  NOTIFICATION_COLLECTION_NAME
);

const notificationStatusCollectionUrl = documentDbUtils.getCollectionUri(
  documentDbDatabaseUrl,
  NOTIFICATION_STATUS_COLLECTION_NAME
);

export const WEBHOOK_NOTIFICATION_QUEUE_NAME = "webhooknotifications";
const queueConnectionString = getRequiredStringEnv("QueueStorageConnection");

// We create the db client, services and models here
// as if any error occurs during the construction of these objects
// that would be unrecoverable anyway and we neither may trig a retry
const documentClient = new DocumentDBClient(cosmosDbUri, {
  masterKey: cosmosDbKey
});

const notificationStatusModel = new NotificationStatusModel(
  documentClient,
  notificationStatusCollectionUrl
);

const notificationModel = new NotificationModel(
  documentClient,
  notificationsCollectionUrl
);

// As we cannot use Functions bindings to do retries,
// we resort to update the message visibility timeout
// using the queue service (client for Azure queue storage)

documentdb

Azure Cosmos DB Service Node.js SDK for SQL API

MIT
Latest version published 6 years ago

Package Health Score

50 / 100
Full package analysis

Popular documentdb functions