Last active
August 30, 2018 20:39
-
-
Save garystafford/83ee9b59f3ab0c1b26b0f71f6a429640 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
// author: Gary A. Stafford | |
// site: https://programmaticponderings.com | |
// license: MIT License | |
// Reference: https://docs.microsoft.com/en-us/azure/cosmos-db/mongodb-samples | |
// Insert Azure Facts into Cosmos DB Collection | |
'use strict'; | |
/* CONSTANTS */ | |
const mongoClient = require('mongodb').MongoClient; | |
const assert = require('assert'); | |
const COSMOS_DB_CONN_STR = process.env.COSMOS_DB_CONN_STR; | |
const DB_COLLECTION = "azuretechfacts"; | |
const azureFacts = [ | |
{ | |
"fact": "certifications", | |
"title": "Azure Certifications", | |
"image": "image-06.png", | |
"response": "As of June 2018, Microsoft offered ten Azure certification exams, allowing IT professionals the ability to differentiate themselves and validate their knowledge and skills." | |
}, | |
{ | |
"fact": "cognitive", | |
"title": "Cognitive Services", | |
"image": "image-09.png", | |
"response": "Azure's intelligent algorithms allow apps to see, hear, speak, understand and interpret user needs through natural methods of communication." | |
}, | |
{ | |
"fact": "competition", | |
"title": "Azure's Competition", | |
"image": "image-05.png", | |
"response": "According to the G2 Crowd website, Azure's Cloud competitors include Amazon Web Services (AWS), Digital Ocean, Google Compute Engine (GCE), and Rackspace." | |
}, | |
{ | |
"fact": "compliance", | |
"title": "Compliance", | |
"image": "image-06.png", | |
"response": "Microsoft provides the most comprehensive set of compliance offerings (including certifications and attestations) of any cloud service provider." | |
}, | |
{ | |
"fact": "cosmos", | |
"title": "Azure Cosmos DB", | |
"image": "image-17.png", | |
"response": "According to Microsoft, Cosmos DB is a globally distributed, multi-model database service, designed for low latency and scalable applications anywhere in the world, with native support for NoSQL." | |
}, | |
{ | |
"fact": "kubernetes", | |
"title": "Azure Kubernetes Service (AKS)", | |
"image": "image-18.png", | |
"response": "According to Microsoft, Azure Kubernetes Service (AKS) is a fully managed Kubernetes container orchestration service, which simplifies Kubernetes management, deployment, and operations." | |
} | |
]; | |
const insertDocuments = function (db, callback) { | |
db.collection(DB_COLLECTION).insertMany(azureFacts, function (err, result) { | |
assert.equal(err, null); | |
console.log(`Inserted documents into the ${DB_COLLECTION} collection.`); | |
callback(); | |
}); | |
}; | |
const findDocuments = function (db, callback) { | |
const cursor = db.collection(DB_COLLECTION).find(); | |
cursor.each(function (err, doc) { | |
assert.equal(err, null); | |
if (doc != null) { | |
console.dir(doc); | |
} else { | |
callback(); | |
} | |
}); | |
}; | |
const deleteDocuments = function (db, callback) { | |
db.collection(DB_COLLECTION).deleteMany( | |
{}, | |
function (err, results) { | |
console.log(results); | |
callback(); | |
} | |
); | |
}; | |
mongoClient.connect(COSMOS_DB_CONN_STR, function (err, client) { | |
assert.equal(null, err); | |
const db = client.db(DB_COLLECTION); | |
deleteDocuments(db, function () { | |
insertDocuments(db, function () { | |
findDocuments(db, function () { | |
client.close(); | |
}); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment