Last active
May 18, 2016 08:11
-
-
Save kanreisa/2ba3e9bf93b777380d46d7ece23b33cf to your computer and use it in GitHub Desktop.
This file contains 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
"use strict"; | |
const http = require("http"); | |
const DocumentClient = require('documentdb-q-promises').DocumentClientWrapper; | |
const host = "https://<name>.documents.azure.com:443/";// Add your endpoint | |
const masterKey = "...";// Add the masterkey of the endpoint | |
const client = new DocumentClient(host, { masterKey: masterKey }); | |
// DB, Collection, Document 生成コードは面倒なので省きました。 | |
// counter document's _SELF | |
const documentId = "dbs/.../colls/.../docs/.../"; | |
const server = http.createServer((req, res) => { | |
res.setHeader("Content-Type", "text/plain"); | |
res.writeHead(200); | |
let startAt = Date.now(); | |
let readTime = -1; | |
client.readDocumentAsync(documentId) | |
.then(doc => { | |
readTime = Date.now() - startAt; | |
++doc.resource.count; | |
startAt = Date.now(); | |
return client.replaceDocumentAsync(doc.resource._self, doc.resource); | |
}) | |
.then(doc => { | |
res.end(`This is DocumentDB Read/Update Demo. -> count=${doc.resource.count} (r/w: ${readTime}/${Date.now() - startAt} ms)`); | |
}) | |
.fail(err => { | |
console.error("error!", err); | |
res.end(JSON.stringify(err)); | |
}); | |
}); | |
server.listen(process.env.PORT); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment