We recently announced deprecation of JS v1 SDK and this repo. Starting September 2020 Microsoft will not provide support for this library. Existing applications using library will continue to work as-is. We strongly recommend upgrading to @azure/cosmos library.
Перейти к файлу
Ryan CrawCour 0707659e4d Update LICENSE 2014-08-25 14:52:10 -07:00
lib DocumentDB nodejs sdk 2014-08-22 23:54:11 -07:00
test DocumentDB nodejs sdk 2014-08-22 23:54:11 -07:00
LICENSE Update LICENSE 2014-08-25 14:52:10 -07:00
index.js DocumentDB nodejs sdk 2014-08-22 23:54:11 -07:00
package.json DocumentDB nodejs sdk 2014-08-22 23:54:11 -07:00
readme.md Remove head element from readme.md 2014-08-23 01:28:50 -07:00

readme.md

<html>

Windows Azure DocumentDB nodejs SDK

DocumentDB is a purpose built NoSQL JSON document database designed for modern mobile and web applications. DocumentDB supports rich queries over JSON data as well as transactional execution of JavaScript based application logic.
DocumentDB is built with a deep commitment to the JSON data model enabling it to offer differentiated query and data processing capabilities that scale to meet the needs of the most demanding modern applications.

The Nodejs sdk has two API models:
Callback model: where all calls use callbacks for responses and this is exposed in DocumentClient.
Promises model: where all calls use Q promises for responses ( this one is built on top of the callback model and this is exposed in DocumentClientWrapper.

Installing the library using npm

npm install documentdb

Hello world example code using callbacks

var DocumentClient = require('documentdb').DocumentClient;

var host = [hostendpoint]; // Add your endpoint var masterKey = [database account masterkey]; // Add the massterkey of the endpoint

var client = new DocumentClient(host, {masterKey: masterKey}); var databaseDefinition = { id: "sample database" }; var collectionDefinition = { id: "sample collection" }; var documentDefinition = { id: "hello world doc", content: "Hello World!" };

client.createDatabase(databaseDefinition, function(err, database) { if(err) return console.log(err); console.log('created db');

client.createCollection(database._self, collectionDefinition, function(err, collection) {
    if(err) return console.log(err);
	
    console.log('created collection');
    
    client.createDocument(collection._self, documentDefinition, function(err, document) {
        if(err) return console.log(err);
		
        console.log('Created Document with content: ', document.content);
    });
});

});

function cleanup(client, database) { client.deleteDatabase(database._self, function(err) { if(err) console.log(err); }); }

Hello world example code using Q promises

var DocumentClient = require('documentdb').DocumentClientWrapper;

var host = [hostendpoint]; // Add your endpoint var masterKey = [database account masterkey]; // Add the massterkey of the endpoint

var client = new DocumentClient(host, {masterKey: masterKey}); var databaseDefinition = { id: "sample database" } var collectionDefinition = { id: "sample collection" }; var documentDefinition = { id: "hello world doc", content: "Hello World!" };

var database, collection, document; client.createDatabaseAsync(databaseDefinition) .then(function(databaseResponse) { database = databaseResponse.resource; return client.createCollectionAsync(database._self, collectionDefinition); }) .then(function(collectionResponse) { collection = collectionResponse.resource;

    return client.createDocumentAsync(collection._self, documentDefinition);
})
.then(function(documentResponse) {
	var document = documentResponse.resource;
	console.log('Created Document with content: ', document.content);
    cleanup(client, database);
})
.fail(function(error) {
    console.log("An error occured", error);
});

function cleanup(client, database) { client.deleteDatabaseAsync(database._self) .then(function(response) { console.log('clean up completed'); }) .fail(function(error){ console.log(error); }); }

Running the tests

  
First You need to install mocha and q
> npm install mocha
> npm install q

From the nodejsclient folder run > mocha -t 50000 -R spec

</html>