SlideShare ist ein Scribd-Unternehmen logo
1 von 63
Getting Started With MongoDB and
Node.JS
Jay Runkel
Principal Solutions Architect
jay.runkel@mongodb.com
@jayrunkel
2
3
GridFS
Driver
GridFS API
doc.jpg
(meta
data)
doc.jpg
(1)doc.jpg
(1)doc.jpg
(1)
fs.files fs.chunks
doc.jpg
4
5
Perl? What is this 1985?
6
Goal Today
• Help you get started with MongoDB and Node.JS
• Assumption:
– New to both technologies
– Programming Experience
– Database Experience
• Learn from my newbie confusion
7
Agenda
1. Why Node.JS and MongoDB?
2. Find and Insert
3. Node.JS async, event queue, flow control
4. Controlling multiple threads
– Bulk insert
MongoDB and Node.JS?
9
Marriage Made in Heaven
10
JavaScript and “JSON” throughout
Browser
JavaScript
Node.JS
JavaScriptJSON
BSON (JSON)
BSON
JSON
11
Documents are Rich Data Structures
{
first_name: ‘Paul’,
surname: ‘Miller’,
cell: ‘+447557505611’
city: ‘London’,
location: [45.123,47.232],
Profession: [banking, finance, trader],
cars: [
{ model: ‘Bentley’,
year: 1973,
value: 100000, … },
{ model: ‘Rolls Royce’,
year: 1965,
value: 330000, … }
]
}
Fields can contain an array of sub-documents
Fields
Typed field values
Fields can contain arrays
Do More With Your Data
MongoDB
{
first_name: ‘Paul’,
surname: ‘Miller’,
city: ‘London’,
location: [45.123,47.232],
cars: [
{ model: ‘Bentley’,
year: 1973,
value: 100000, … },
{ model: ‘Rolls Royce’,
year: 1965,
value: 330000, … }
}
}
Rich Queries
Find Paul’s cars
Find everybody in London with a car
built between 1970 and 1980
Geospatial
Find all of the car owners within 5km
of Trafalgar Sq.
Text Search
Find all the cars described as having
leather seats
Aggregation
Calculate the average value of Paul’s
car collection
Map Reduce
What is the ownership pattern of
colors by geography over time?
(is purple trending up in China?)
13
Aircraft Sensor
RTL-SDR
14
Sample Data
{
"_id" : "20160101000000:UA7549",
"icao" : "UA7549",
"callsign" : "UA7549",
"ts" : ISODate("2016-01-01T05:00:00Z"),
"events" : {
"a" : 1773,
"b" : 258,
"p" : [50,-60],
"s" : 345,
"t" : ISODate("2016-01-01T05:00:00Z"),
"v" : 299
}
}
15
Example: Find Query
• Find a flight status entry for United Airlines Flight 1234
– db.data.findOne({"callsign" : "UA7549"})
• Find a aircraft flying at less than 5000 feet
– db.data.findOne({"events.a" : {$lt : 5000}})
• Set value of note field
– db.data.update({"callsign" : "OY1949"},
{$set : {"note" : "spoke with captain"}})
Retrieve One Document in Node.JS
The Simple Things Don’t Always Seem Easy
17
The synchronous way
var MongoClient = require('mongodb').MongoClient;
var db = MongoClient.connect('mongodb://localhost:27017/adsb');
var col = db.collection('data');
var doc = col.findOne({"callsign" : "UA7549"});
console.log("Here is my doc: %j", doc);
db.close();
18
The synchronous way
var MongoClient = require('mongodb').MongoClient;
var db = MongoClient.connect('mongodb://localhost:27017/adsb');
var col = db.collection('data');
var doc = col.findOne({"callsign" : "UA7549"});
console.log("Here is my doc: %j", doc);
db.close();
19
It works this way in the mongoshell???
var col = db.getCollection("data");
var doc = col.findOne({"callsign" : "HR9368"});
printjson(doc);
Synchronous vs. Asychronous
Event Loop
21
Synchronous Programming
time
Func1 Func1 IO Func1 Func2 Func2 IO Func2
22
Asynchronous Programming
time
Func1
Func1 IO
Func1Func2
Func2 IO
Func2
IO Processing runs on separate
threads in parallel with main
processing thread
23
Callbacks
col.findOne({"callsign" : "UA7549"}, function (err, doc) {
assert.equal(null, err);
console.log("Here is my doc: %j", doc);
console.log(”All done!”);
• Execute findOne
• When it is done, call the callback function
• Callback function takes two arguments
– err – contains the error message or null
– doc – the result of the findOne call
• “All Done” will be printed before the “Here is my doc…”
24
Event queue
From: http://www.slideshare.net/takingblue/talk-nodejs-andisomorphicjavascript
25
Event queue
From: http://www.slideshare.net/takingblue/talk-nodejs-andisomorphicjavascript
MongoDB
26
Event Queue/Call Stack
function find1234 () {
col.findOne({_id: 1234},
fo1_cb);
find1234();
col.updateMany({color: “blue”},
{$set : {w : 5}}, up1_cb);
col.insert({product: 1234,
cost: 99}, ins1_cb);
console.log(“done”);
Call Stack Driver API
Callback
Queue
Event Loop
27
Event Queue/Call Stack
function find1234 () {
col.findOne({_id: 1234},
fo1_cb);
find1234();
col.updateMany({color: “blue”},
{$set : {w : 5}}, up1_cb);
col.insert({product: 1234,
cost: 99}, ins1_cb);
console.log(“done”);
Call Stack Driver API
Callback
Queue
Event Loop
find1234()
28
Event Queue/Call Stack
function find1234 () {
col.findOne({_id: 1234},
fo1_cb);
find1234();
col.updateMany({color: “blue”},
{$set : {w : 5}}, up1_cb);
col.insert({product: 1234,
cost: 99}, ins1_cb);
console.log(“done”);
Call Stack Driver API
Callback
Queue
Event Loop
find1234()
col.findOne()
col.findOne()
29
Event Queue/Call Stack
function find1234 () {
col.findOne({_id: 1234},
fo1_cb);
find1234();
col.updateMany({color: “blue”},
{$set : {w : 5}}, up1_cb);
col.insert({product: 1234,
cost: 99}, ins1_cb);
console.log(“done”);
Call Stack Driver API
Callback
Queue
Event Loop
col.updateMany()
col.findOne()
col.updateMany()
30
Event Queue/Call Stack
function find1234 () {
col.findOne({_id: 1234},
fo1_cb);
find1234();
col.updateMany({color: “blue”},
{$set : {w : 5}}, up1_cb);
col.insert({product: 1234,
cost: 99}, ins1_cb);
console.log(“done”);
Call Stack Driver API
Callback
Queue
Event Loop
col.insert()
col.insert()
col.updateMany()
fo1_cb
31
Event Queue/Call Stack
function find1234 () {
col.findOne({_id: 1234},
fo1_cb);
find1234();
col.updateMany({color: “blue”},
{$set : {w : 5}}, up1_cb);
col.insert({product: 1234,
cost: 99}, ins1_cb);
console.log(“done”);
Call Stack Driver API
Callback
Queue
Event Loop
console.log()
col.updateMany()
fo1_cb ins1_cb
32
Event Queue/Call Stack
function find1234 () {
col.findOne({_id: 1234},
fo1_cb);
find1234();
col.updateMany({color: “blue”},
{$set : {w : 5}}, up1_cb);
col.insert({product: 1234,
cost: 99}, ins1_cb);
console.log(“done”);
function fo1_cb () {…}
Call Stack Driver API
Callback
Queue
Event Loop
fo1_cb()
col.updateMany()
ins1_cb
33
Event Queue/Call Stack
Call Stack Driver API
Callback
Queue
Event Loop
ins1_cb()
up1_cb
function find1234 () {
col.findOne({_id: 1234},
fo1_cb);
find1234();
col.updateMany({color: “blue”},
{$set : {w : 5}}, up1_cb);
col.insert({product: 1234,
cost: 99}, ins1_cb);
console.log(“done”);
function ins1_cb () {…}
34
Event Queue/Call Stack
Call Stack Driver API
Callback
Queue
Event Loop
up1_cb()
function find1234 () {
col.findOne({_id: 1234},
fo1_cb);
find1234();
col.updateMany({color: “blue”},
{$set : {w : 5}}, up1_cb);
col.insert({product: 1234,
cost: 99}, ins1_cb);
console.log(“done”);
function up1_cb () {…}
Back to the findOne example
36
MongoDB Asynchronous Queries
var MongoClient = require('mongodb').MongoClient,
assert = require('assert');
MongoClient.connect('mongodb://localhost:27017/adsb', function (err, db) {
assert.equal(null, err);
var col = db.collection('data');
col.findOne({"callsign" : "UA7549"}, function (err, doc) {
assert.equal(null, err);
console.log("Here is my doc: %j", doc);
db.close();
});
});
37
Asynchronously
var MongoClient = require('mongodb').MongoClient,
assert = require('assert');
MongoClient.connect('mongodb://localhost:27017/adsb', function (err, db) {
assert.equal(null, err);
var col = db.collection('data');
col.findOne({"callsign" : "UA7549"}, function (err, doc) {
assert.equal(null, err);
console.log("Here is my doc: %j", doc);
db.close();
});
});
callback
38
Asynchronously
var MongoClient = require('mongodb').MongoClient,
assert = require('assert');
MongoClient.connect('mongodb://localhost:27017/adsb', function (err, db) {
assert.equal(null, err);
var col = db.collection('data');
col.findOne({"callsign" : "UA7549"}, function (err, doc) {
assert.equal(null, err);
console.log("Here is my doc: %j", doc);
db.close();
});
});
callback
39
This gets ugly fast
var MongoClient = require('mongodb').MongoClient,
assert = require('assert');
var db = MongoClient.connect('mongodb://localhost:27017/adsb', function (err, db) {
assert.equal(null, err);
var col = db.collection('data');
col.findOne({"callsign" : "UA7549"}, function (err, doc) {
assert.equal(null, err);
console.log("Here is my doc: %j", doc);
col.updateOne({"callsign" : "UA7549"}, {$set : {"note" : "Spoke with the
pilot"}}, {}, function(err, result) {
assert.equal(null, err);
console.log("Note updated");
db.close();
});
});
});
40
Nested callbacks - yuck
async1(function(input, result1) {
async2(function(result2) {
async3(function(result3) {
async4(function(result4) {
async5(function(output) {
// do something with output
});
});
});
});
})
41
Solutions
• Break up into modules
• Use a Flow Control library
– async
– Step
• Promises
42
With Flow Control - Step
Step (
function connectToMongoDB (err, db) {
MongoClient.connect('mongodb://
localhost:27017/adsb', this);
},
function findOneDoc(err, db) {
if (err) console.log("Connect: %j",
err);
database = db;
collection = db.collection('data');
collection.findOne(csQuery, {}, this);
},
function updateDoc(err, doc) {
if (err) console.log("Find One: %j",
err);
console.log("Here is my doc: %j", doc);
collection.updateOne(csQuery,
{$inc : {"timesViewed" : 1}},{},this);
},
function findOneDoc2 (err, result) {
if (err)
console.log("Update error: %j", err);
collection.findOne(csQuery, {},
this);
},
function closeConnection(err, doc) {
if (err)
console.log("FindOne Doc: %j", err);
console.log("Note updated: %j",
doc);
database.close();
}
);
43
With Flow Control
Step (
function connectToMongoDB (err, db) {
MongoClient.connect('mongodb://
localhost:27017/adsb', this);
},
function findOneDoc(err, db) {
if (err) console.log("Connect: %j",
err);
database = db;
collection = db.collection('data');
collection.findOne(csQuery, {}, this);
},
function updateDoc(err, doc) {
if (err) console.log("Find One: %j",
err);
console.log("Here is my doc: %j", doc);
collection.updateOne(csQuery,
{$inc : {"timesViewed" : 1}},{},this);
},
function findOneDoc2 (err, result) {
if (err)
console.log("Update error: %j", err);
collection.findOne(csQuery, {},
this);
},
function closeConnection(err, doc) {
if (err)
console.log("FindOne Doc: %j", err);
console.log("Note updated: %j",
doc);
database.close();
}
44
With Flow Control
Step (
function connectToMongoDB (err, db) {
MongoClient.connect('mongodb://
localhost:27017/adsb', this);
},
function findOneDoc(err, db) {
if (err) console.log("Connect: %j",
err);
database = db;
collection = db.collection('data');
collection.findOne(csQuery, {}, this);
},
function updateDoc(err, doc) {
if (err) console.log("Find One: %j",
err);
console.log("Here is my doc: %j", doc);
collection.updateOne(csQuery,
{$inc : {"timesViewed" : 1}},{},this);
},
function findOneDoc2 (err, result) {
if (err)
console.log("Update error: %j", err);
collection.findOne(csQuery, {},
this);
},
function closeConnection(err, doc) {
if (err)
console.log("FindOne Doc: %j", err);
console.log("Note updated: %j",
doc);
database.close();
}
45
You can also execute in parallel
Step (
function connectToMongoDB (err, db) {
MongoClient.connect('mongodb://localhost:27017/adsb', this);
},
function executeParallel (err, db) {
if (err) console.log("Connect: %j", err);
var collection = db.collection('data');
database = db;
collection.findOne(csQuery, {}, this.parallel());
collection.updateOne(csQuery, {$inc : {"timesViewed" : 1}}, {}, this.parallel());
collection.findOne(csQuery, {}, this.parallel());
},
function closeConnection(err, doc1, upResult, doc2) {
if (err) console.log("Error: %j", err);
console.log("Here is doc1: %j", doc1);
console.log("Incremented: %j", upResult);
console.log("Here is doc2: %j", doc2);
database.close();
}
);
How do you deal with multiple find results?
47
Find Many - Cursor
• This works in the MongoShell
var col = db.getCollection("data");
var cursor = col.find({"events.a" : {$gt : 5000}});
while (cursor.hasNext()) {
printjson(cursor.next());
}
48
Find Many - Cursor
• This works in the MongoShell
var col = db.getCollection("data");
var cursor = col.find({"events.a" : {$gt : 5000}});
while (cursor.hasNext()) {
printjson(cursor.next());
}
• It does not work in Node.JS
• The MongoDB driver retrieves documents in batches from MongoDB
– Retrieving a new batch is asynchronous
49
Find Many - Streams
MongoClient.connect("mongodb://localhost:27017/adsb", function (err, db) {
var col = db.collection('data')
var stream = col.find({"events.a" : {$gt : 5000}}).stream();
stream.on('data', function(doc) {
console.log("Doc: %j", doc);
});
stream.on('error', function (doc) {
console.log("Query failed: %j", doc);
});
stream.on('end', function() {
console.log("All data retrieved.");
db.close();
});
});
50
Find Many - Streams
MongoClient.connect("mongodb://localhost:27017/adsb", function (err, db) {
var col = db.collection('data')
var stream = col.find({"events.a" : {$gt : 5000}}).stream();
stream.on('data', function(doc) {
console.log("Doc: %j", doc);
});
stream.on('error', function (doc) {
console.log("Query failed: %j", doc);
});
stream.on('end', function() {
console.log("All data retrieved.");
db.close();
});
});
‘data’ callback invoked
for each document
51
What about insert?
MongoClient.connect('mongodb://localhost:27017/adsb', function (err, db) {
assert.equal(null, err);
var col = db.collection('data');
col.insert({x: 1, y: 2, z: 3},
{},
function (err, result) {
assert.equal(null, err);
console.log("Insert Complete");
db.close();
});
});
52
What if I have to insert 100M documents?
MongoClient.connect('mongodb://localhost:27017/adsb', function (err, db) {
assert.equal(null, err);
var col = db.collection('data');
for (i = 1; i <= 100000000; i++) {
col.insert({x: i, y: 2, z: 3},
{},
function (err, result) {
assert.equal(null, err);
console.log("Insert Complete");
});
}
});
Let’s insert all 100,000,000
in parallel!!!!
53
What if I have to insert 100M documents?
MongoClient.connect('mongodb://localhost:27017/adsb', function (err, db) {
assert.equal(null, err);
var col = db.collection('data');
for (i = 1; i <= 100000000; i++) {
col.insert({x: i, y: 2, z: 3},
{},
function (err, result) {
assert.equal(null, err);
console.log("Insert Complete");
db.close();
});
}
});
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
54
Event Queue/Call Stack
for (i = 1; i <= 100000000; i++) {
col.insert({x: i, y: 2, z: 3},
{},
function (err, result) {
assert.equal(null, err);
console.log("Insert C…");
});
}
Call Stack Driver API
Callback
Queue
Event Loop
55
Event Queue/Call Stack
for (i = 1; i <= 100000000; i++) {
col.insert({x: i, y: 2, z: 3},
{},
function (err, result) {
assert.equal(null, err);
console.log("Insert C…");
db.close();
});
Call Stack Driver API
Callback
Queue
Event Loop
col.insert()
col.insert()
col.insert()
col.insert()
col.insert()
col.insert()
col.insert()
col.insert()
col.insert()
56
Event Queue/Call Stack
for (i = 1; i <= 100000000; i++) {
col.insert({x: i, y: 2, z: 3},
{},
function (err, result) {
assert.equal(null, err);
console.log("Insert C…");
db.close();
});
Call Stack Driver API
Callback
Queue
Event Loop
col.insert()
col.insert()
col.insert()
col.insert()
col.insert()
col.insert()
col.insert()
col.insert()
col.insert()
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
57
Let’s try 5 at a time
var DOCS_TO_INSERT = 1000;
var numInsertsRunning = 0; // number of insert threads
var insertCount = 0; // number of documents inserted so far
MongoClient.connect('mongodb://localhost:27017/adsb', function (err, db) {
assert.equal(null, err);
var col = db.collection('data');
for (i = 0; i < 5; i++) {
++numInsertsRunning;
insertDocument(db, col, ++insertCount, i, function (err, result) {
console.log("All ", DOCS_TO_INSERT, " documents inserted.");
db.close();
});
}
});
58
insertDocument function
function insertDocument (db, col, docNum, threadNum, callback) {
col.insert({x: ++insertCount, y: 2, z: 3},
{},
function (err, result) {
assert.equal(null, err);
console.log("Thread: ", threadNum, " inserted doc: ", docNum, ".");
if (insertCount < DOCS_TO_INSERT)
insertDocument(db, col, ++insertCount, threadNum, callback);
else if (numInsertsRunning == 1) {
numInsertsRunning--;
callback(null, true);
}
else
numInsertsRunning--;
});
}
59
InsertDocument Callback Logic
col.insert({x: ++insertCount, y: 2, z: 3}, function (err, result) {
}
Have all the documents
been inserted?
Call insertDocument
again
Are other inserts still
running?
Do nothing & decrement
running thread count
All inserts done
Call the original callback
Yes Yes
No No
60
Bulk Inserts
• The previous example was for illustrative purposes
• MongoDB provides a buik write API that provides better performance for bulk writes
• The bulk write API batches up writes
– Batch writes with a single acknowledgement
• Use collection.bulkWrite
• Improve performance using multiple bulkWrite threads
– Previous example will be identical
– Replace collection.insert with collection.bulkWrite
61
Another word of caution
• All my examples established a MongoDB connection and then closed it
– This was for illustrative purposes
• Don’t continuously open and close MongoDB connections.
• Open a connection once once
– Use that connection through the life of the program
– Close it at the end
62
Summary
• Asynchronous vs synchronous programming
• Call stack, event loop, driver API
• Flow control
• Find, insert, update examples
• Managing multiple parallel threads
– bulk insert example
• Learn from my mistakes and misconceptions
Questions?
jay.runkel@mongodb.com
@jayrunkel
Github: https://github.com/jayrunkel/nodeJSWebJun2016

Weitere ähnliche Inhalte

Was ist angesagt?

MongoDB + Java - Everything you need to know
MongoDB + Java - Everything you need to know MongoDB + Java - Everything you need to know
MongoDB + Java - Everything you need to know Norberto Leite
 
MongoDB Aggregation
MongoDB Aggregation MongoDB Aggregation
MongoDB Aggregation Amit Ghosh
 
Java development with MongoDB
Java development with MongoDBJava development with MongoDB
Java development with MongoDBJames Williams
 
MongoDB Europe 2016 - Debugging MongoDB Performance
MongoDB Europe 2016 - Debugging MongoDB PerformanceMongoDB Europe 2016 - Debugging MongoDB Performance
MongoDB Europe 2016 - Debugging MongoDB PerformanceMongoDB
 
Hadoop - MongoDB Webinar June 2014
Hadoop - MongoDB Webinar June 2014Hadoop - MongoDB Webinar June 2014
Hadoop - MongoDB Webinar June 2014MongoDB
 
Inside MongoDB: the Internals of an Open-Source Database
Inside MongoDB: the Internals of an Open-Source DatabaseInside MongoDB: the Internals of an Open-Source Database
Inside MongoDB: the Internals of an Open-Source DatabaseMike Dirolf
 
Webinar: Index Tuning and Evaluation
Webinar: Index Tuning and EvaluationWebinar: Index Tuning and Evaluation
Webinar: Index Tuning and EvaluationMongoDB
 
Joins and Other Aggregation Enhancements Coming in MongoDB 3.2
Joins and Other Aggregation Enhancements Coming in MongoDB 3.2Joins and Other Aggregation Enhancements Coming in MongoDB 3.2
Joins and Other Aggregation Enhancements Coming in MongoDB 3.2MongoDB
 
Webinar: Building Your First App with MongoDB and Java
Webinar: Building Your First App with MongoDB and JavaWebinar: Building Your First App with MongoDB and Java
Webinar: Building Your First App with MongoDB and JavaMongoDB
 
MongoDB World 2016: Deciphering .explain() Output
MongoDB World 2016: Deciphering .explain() OutputMongoDB World 2016: Deciphering .explain() Output
MongoDB World 2016: Deciphering .explain() OutputMongoDB
 
Back to Basics: My First MongoDB Application
Back to Basics: My First MongoDB ApplicationBack to Basics: My First MongoDB Application
Back to Basics: My First MongoDB ApplicationMongoDB
 
Webinarserie: Einführung in MongoDB: “Back to Basics” - Teil 3 - Interaktion ...
Webinarserie: Einführung in MongoDB: “Back to Basics” - Teil 3 - Interaktion ...Webinarserie: Einführung in MongoDB: “Back to Basics” - Teil 3 - Interaktion ...
Webinarserie: Einführung in MongoDB: “Back to Basics” - Teil 3 - Interaktion ...MongoDB
 
MongoDB .local Toronto 2019: Using Change Streams to Keep Up with Your Data
MongoDB .local Toronto 2019: Using Change Streams to Keep Up with Your DataMongoDB .local Toronto 2019: Using Change Streams to Keep Up with Your Data
MongoDB .local Toronto 2019: Using Change Streams to Keep Up with Your DataMongoDB
 
MongoDB Performance Tuning
MongoDB Performance TuningMongoDB Performance Tuning
MongoDB Performance TuningMongoDB
 
Mythbusting: Understanding How We Measure the Performance of MongoDB
Mythbusting: Understanding How We Measure the Performance of MongoDBMythbusting: Understanding How We Measure the Performance of MongoDB
Mythbusting: Understanding How We Measure the Performance of MongoDBMongoDB
 
MongoDB Aggregation Framework
MongoDB Aggregation FrameworkMongoDB Aggregation Framework
MongoDB Aggregation FrameworkCaserta
 
Indexing Strategies to Help You Scale
Indexing Strategies to Help You ScaleIndexing Strategies to Help You Scale
Indexing Strategies to Help You ScaleMongoDB
 
2014 bigdatacamp asya_kamsky
2014 bigdatacamp asya_kamsky2014 bigdatacamp asya_kamsky
2014 bigdatacamp asya_kamskyData Con LA
 
Aggregation Framework MongoDB Days Munich
Aggregation Framework MongoDB Days MunichAggregation Framework MongoDB Days Munich
Aggregation Framework MongoDB Days MunichNorberto Leite
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDBNosh Petigara
 

Was ist angesagt? (20)

MongoDB + Java - Everything you need to know
MongoDB + Java - Everything you need to know MongoDB + Java - Everything you need to know
MongoDB + Java - Everything you need to know
 
MongoDB Aggregation
MongoDB Aggregation MongoDB Aggregation
MongoDB Aggregation
 
Java development with MongoDB
Java development with MongoDBJava development with MongoDB
Java development with MongoDB
 
MongoDB Europe 2016 - Debugging MongoDB Performance
MongoDB Europe 2016 - Debugging MongoDB PerformanceMongoDB Europe 2016 - Debugging MongoDB Performance
MongoDB Europe 2016 - Debugging MongoDB Performance
 
Hadoop - MongoDB Webinar June 2014
Hadoop - MongoDB Webinar June 2014Hadoop - MongoDB Webinar June 2014
Hadoop - MongoDB Webinar June 2014
 
Inside MongoDB: the Internals of an Open-Source Database
Inside MongoDB: the Internals of an Open-Source DatabaseInside MongoDB: the Internals of an Open-Source Database
Inside MongoDB: the Internals of an Open-Source Database
 
Webinar: Index Tuning and Evaluation
Webinar: Index Tuning and EvaluationWebinar: Index Tuning and Evaluation
Webinar: Index Tuning and Evaluation
 
Joins and Other Aggregation Enhancements Coming in MongoDB 3.2
Joins and Other Aggregation Enhancements Coming in MongoDB 3.2Joins and Other Aggregation Enhancements Coming in MongoDB 3.2
Joins and Other Aggregation Enhancements Coming in MongoDB 3.2
 
Webinar: Building Your First App with MongoDB and Java
Webinar: Building Your First App with MongoDB and JavaWebinar: Building Your First App with MongoDB and Java
Webinar: Building Your First App with MongoDB and Java
 
MongoDB World 2016: Deciphering .explain() Output
MongoDB World 2016: Deciphering .explain() OutputMongoDB World 2016: Deciphering .explain() Output
MongoDB World 2016: Deciphering .explain() Output
 
Back to Basics: My First MongoDB Application
Back to Basics: My First MongoDB ApplicationBack to Basics: My First MongoDB Application
Back to Basics: My First MongoDB Application
 
Webinarserie: Einführung in MongoDB: “Back to Basics” - Teil 3 - Interaktion ...
Webinarserie: Einführung in MongoDB: “Back to Basics” - Teil 3 - Interaktion ...Webinarserie: Einführung in MongoDB: “Back to Basics” - Teil 3 - Interaktion ...
Webinarserie: Einführung in MongoDB: “Back to Basics” - Teil 3 - Interaktion ...
 
MongoDB .local Toronto 2019: Using Change Streams to Keep Up with Your Data
MongoDB .local Toronto 2019: Using Change Streams to Keep Up with Your DataMongoDB .local Toronto 2019: Using Change Streams to Keep Up with Your Data
MongoDB .local Toronto 2019: Using Change Streams to Keep Up with Your Data
 
MongoDB Performance Tuning
MongoDB Performance TuningMongoDB Performance Tuning
MongoDB Performance Tuning
 
Mythbusting: Understanding How We Measure the Performance of MongoDB
Mythbusting: Understanding How We Measure the Performance of MongoDBMythbusting: Understanding How We Measure the Performance of MongoDB
Mythbusting: Understanding How We Measure the Performance of MongoDB
 
MongoDB Aggregation Framework
MongoDB Aggregation FrameworkMongoDB Aggregation Framework
MongoDB Aggregation Framework
 
Indexing Strategies to Help You Scale
Indexing Strategies to Help You ScaleIndexing Strategies to Help You Scale
Indexing Strategies to Help You Scale
 
2014 bigdatacamp asya_kamsky
2014 bigdatacamp asya_kamsky2014 bigdatacamp asya_kamsky
2014 bigdatacamp asya_kamsky
 
Aggregation Framework MongoDB Days Munich
Aggregation Framework MongoDB Days MunichAggregation Framework MongoDB Days Munich
Aggregation Framework MongoDB Days Munich
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 

Andere mochten auch

Back to Basics Webinar 3: Schema Design Thinking in Documents
 Back to Basics Webinar 3: Schema Design Thinking in Documents Back to Basics Webinar 3: Schema Design Thinking in Documents
Back to Basics Webinar 3: Schema Design Thinking in DocumentsMongoDB
 
Back to Basics, webinar 1: Introduzione a NoSQL
Back to Basics, webinar 1: Introduzione a NoSQLBack to Basics, webinar 1: Introduzione a NoSQL
Back to Basics, webinar 1: Introduzione a NoSQLMongoDB
 
MongoDB gridfs
MongoDB gridfsMongoDB gridfs
MongoDB gridfsXue Wei
 
MongoDB Internals
MongoDB InternalsMongoDB Internals
MongoDB InternalsSiraj Memon
 
MongoDB Operations for Developers
MongoDB Operations for DevelopersMongoDB Operations for Developers
MongoDB Operations for DevelopersMongoDB
 
Get expertise with mongo db
Get expertise with mongo dbGet expertise with mongo db
Get expertise with mongo dbAmit Thakkar
 
Gridfs and MongoDB
Gridfs and MongoDBGridfs and MongoDB
Gridfs and MongoDBMitch Pirtle
 
MongoDB- Crud Operation
MongoDB- Crud OperationMongoDB- Crud Operation
MongoDB- Crud OperationEdureka!
 
MongoDB on EC2 and EBS
MongoDB on EC2 and EBSMongoDB on EC2 and EBS
MongoDB on EC2 and EBSJared Rosoff
 
An Enterprise Architect's View of MongoDB
An Enterprise Architect's View of MongoDBAn Enterprise Architect's View of MongoDB
An Enterprise Architect's View of MongoDBMongoDB
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDBEdureka!
 
Introduction to column oriented databases
Introduction to column oriented databasesIntroduction to column oriented databases
Introduction to column oriented databasesArangoDB Database
 
Back to Basics Webinar 6: Production Deployment
Back to Basics Webinar 6: Production DeploymentBack to Basics Webinar 6: Production Deployment
Back to Basics Webinar 6: Production DeploymentMongoDB
 
Webinar: Back to Basics: Thinking in Documents
Webinar: Back to Basics: Thinking in DocumentsWebinar: Back to Basics: Thinking in Documents
Webinar: Back to Basics: Thinking in DocumentsMongoDB
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDBRavi Teja
 

Andere mochten auch (18)

Back to Basics Webinar 3: Schema Design Thinking in Documents
 Back to Basics Webinar 3: Schema Design Thinking in Documents Back to Basics Webinar 3: Schema Design Thinking in Documents
Back to Basics Webinar 3: Schema Design Thinking in Documents
 
Back to Basics, webinar 1: Introduzione a NoSQL
Back to Basics, webinar 1: Introduzione a NoSQLBack to Basics, webinar 1: Introduzione a NoSQL
Back to Basics, webinar 1: Introduzione a NoSQL
 
MongoDB gridfs
MongoDB gridfsMongoDB gridfs
MongoDB gridfs
 
MongoDB Internals
MongoDB InternalsMongoDB Internals
MongoDB Internals
 
MongoDB Operations for Developers
MongoDB Operations for DevelopersMongoDB Operations for Developers
MongoDB Operations for Developers
 
MongoDB
MongoDBMongoDB
MongoDB
 
Get expertise with mongo db
Get expertise with mongo dbGet expertise with mongo db
Get expertise with mongo db
 
Gridfs and MongoDB
Gridfs and MongoDBGridfs and MongoDB
Gridfs and MongoDB
 
MongoDB- Crud Operation
MongoDB- Crud OperationMongoDB- Crud Operation
MongoDB- Crud Operation
 
MongoDB on EC2 and EBS
MongoDB on EC2 and EBSMongoDB on EC2 and EBS
MongoDB on EC2 and EBS
 
An Enterprise Architect's View of MongoDB
An Enterprise Architect's View of MongoDBAn Enterprise Architect's View of MongoDB
An Enterprise Architect's View of MongoDB
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
Introduction to column oriented databases
Introduction to column oriented databasesIntroduction to column oriented databases
Introduction to column oriented databases
 
Back to Basics Webinar 6: Production Deployment
Back to Basics Webinar 6: Production DeploymentBack to Basics Webinar 6: Production Deployment
Back to Basics Webinar 6: Production Deployment
 
Webinar: Back to Basics: Thinking in Documents
Webinar: Back to Basics: Thinking in DocumentsWebinar: Back to Basics: Thinking in Documents
Webinar: Back to Basics: Thinking in Documents
 
Mongo DB
Mongo DBMongo DB
Mongo DB
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
Grid FS
Grid FSGrid FS
Grid FS
 

Ähnlich wie Getting Started with MongoDB and NodeJS

Data Management 3: Bulletproof Data Management
Data Management 3: Bulletproof Data ManagementData Management 3: Bulletproof Data Management
Data Management 3: Bulletproof Data ManagementMongoDB
 
Michael Hackstein - NoSQL meets Microservices - NoSQL matters Dublin 2015
Michael Hackstein - NoSQL meets Microservices - NoSQL matters Dublin 2015Michael Hackstein - NoSQL meets Microservices - NoSQL matters Dublin 2015
Michael Hackstein - NoSQL meets Microservices - NoSQL matters Dublin 2015NoSQLmatters
 
NoSQL meets Microservices - Michael Hackstein
NoSQL meets Microservices - Michael HacksteinNoSQL meets Microservices - Michael Hackstein
NoSQL meets Microservices - Michael Hacksteindistributed matters
 
Javascript Everywhere From Nose To Tail
Javascript Everywhere From Nose To TailJavascript Everywhere From Nose To Tail
Javascript Everywhere From Nose To TailCliffano Subagio
 
Firefox OS, une plateforme à découvrir - IO Saglac - 2014-09-09
Firefox OS, une plateforme à découvrir - IO Saglac - 2014-09-09Firefox OS, une plateforme à découvrir - IO Saglac - 2014-09-09
Firefox OS, une plateforme à découvrir - IO Saglac - 2014-09-09Frédéric Harper
 
MongoDB dla administratora
MongoDB dla administratora MongoDB dla administratora
MongoDB dla administratora 3camp
 
Monitoring Your ISP Using InfluxDB Cloud and Raspberry Pi
Monitoring Your ISP Using InfluxDB Cloud and Raspberry PiMonitoring Your ISP Using InfluxDB Cloud and Raspberry Pi
Monitoring Your ISP Using InfluxDB Cloud and Raspberry PiInfluxData
 
Future of Web Apps: Google Gears
Future of Web Apps: Google GearsFuture of Web Apps: Google Gears
Future of Web Apps: Google Gearsdion
 
Functional Programming In JS
Functional Programming In JSFunctional Programming In JS
Functional Programming In JSDamian Łabas
 
HTML5 for the Silverlight Guy
HTML5 for the Silverlight GuyHTML5 for the Silverlight Guy
HTML5 for the Silverlight GuyDavid Padbury
 
What do you mean, Backwards Compatibility?
What do you mean, Backwards Compatibility?What do you mean, Backwards Compatibility?
What do you mean, Backwards Compatibility?Trisha Gee
 
Herding types with Scala macros
Herding types with Scala macrosHerding types with Scala macros
Herding types with Scala macrosMarina Sigaeva
 
Solutions for bi-directional integration between Oracle RDBMS & Apache Kafka
Solutions for bi-directional integration between Oracle RDBMS & Apache KafkaSolutions for bi-directional integration between Oracle RDBMS & Apache Kafka
Solutions for bi-directional integration between Oracle RDBMS & Apache KafkaGuido Schmutz
 
Solutions for bi-directional Integration between Oracle RDMBS & Apache Kafka
Solutions for bi-directional Integration between Oracle RDMBS & Apache KafkaSolutions for bi-directional Integration between Oracle RDMBS & Apache Kafka
Solutions for bi-directional Integration between Oracle RDMBS & Apache KafkaGuido Schmutz
 
Solutions for bi-directional integration between Oracle RDBMS and Apache Kafk...
Solutions for bi-directional integration between Oracle RDBMS and Apache Kafk...Solutions for bi-directional integration between Oracle RDBMS and Apache Kafk...
Solutions for bi-directional integration between Oracle RDBMS and Apache Kafk...confluent
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with ClojureDmitry Buzdin
 

Ähnlich wie Getting Started with MongoDB and NodeJS (20)

Latinoware
LatinowareLatinoware
Latinoware
 
Mongo db dla administratora
Mongo db dla administratoraMongo db dla administratora
Mongo db dla administratora
 
Data Management 3: Bulletproof Data Management
Data Management 3: Bulletproof Data ManagementData Management 3: Bulletproof Data Management
Data Management 3: Bulletproof Data Management
 
Michael Hackstein - NoSQL meets Microservices - NoSQL matters Dublin 2015
Michael Hackstein - NoSQL meets Microservices - NoSQL matters Dublin 2015Michael Hackstein - NoSQL meets Microservices - NoSQL matters Dublin 2015
Michael Hackstein - NoSQL meets Microservices - NoSQL matters Dublin 2015
 
NoSQL meets Microservices
NoSQL meets MicroservicesNoSQL meets Microservices
NoSQL meets Microservices
 
NoSQL meets Microservices - Michael Hackstein
NoSQL meets Microservices - Michael HacksteinNoSQL meets Microservices - Michael Hackstein
NoSQL meets Microservices - Michael Hackstein
 
Javascript Everywhere From Nose To Tail
Javascript Everywhere From Nose To TailJavascript Everywhere From Nose To Tail
Javascript Everywhere From Nose To Tail
 
Firefox OS, une plateforme à découvrir - IO Saglac - 2014-09-09
Firefox OS, une plateforme à découvrir - IO Saglac - 2014-09-09Firefox OS, une plateforme à découvrir - IO Saglac - 2014-09-09
Firefox OS, une plateforme à découvrir - IO Saglac - 2014-09-09
 
MongoDB dla administratora
MongoDB dla administratora MongoDB dla administratora
MongoDB dla administratora
 
Monitoring Your ISP Using InfluxDB Cloud and Raspberry Pi
Monitoring Your ISP Using InfluxDB Cloud and Raspberry PiMonitoring Your ISP Using InfluxDB Cloud and Raspberry Pi
Monitoring Your ISP Using InfluxDB Cloud and Raspberry Pi
 
Future of Web Apps: Google Gears
Future of Web Apps: Google GearsFuture of Web Apps: Google Gears
Future of Web Apps: Google Gears
 
Functional Programming In JS
Functional Programming In JSFunctional Programming In JS
Functional Programming In JS
 
HTML5 for the Silverlight Guy
HTML5 for the Silverlight GuyHTML5 for the Silverlight Guy
HTML5 for the Silverlight Guy
 
What do you mean, Backwards Compatibility?
What do you mean, Backwards Compatibility?What do you mean, Backwards Compatibility?
What do you mean, Backwards Compatibility?
 
Fact, Fiction, and FP
Fact, Fiction, and FPFact, Fiction, and FP
Fact, Fiction, and FP
 
Herding types with Scala macros
Herding types with Scala macrosHerding types with Scala macros
Herding types with Scala macros
 
Solutions for bi-directional integration between Oracle RDBMS & Apache Kafka
Solutions for bi-directional integration between Oracle RDBMS & Apache KafkaSolutions for bi-directional integration between Oracle RDBMS & Apache Kafka
Solutions for bi-directional integration between Oracle RDBMS & Apache Kafka
 
Solutions for bi-directional Integration between Oracle RDMBS & Apache Kafka
Solutions for bi-directional Integration between Oracle RDMBS & Apache KafkaSolutions for bi-directional Integration between Oracle RDMBS & Apache Kafka
Solutions for bi-directional Integration between Oracle RDMBS & Apache Kafka
 
Solutions for bi-directional integration between Oracle RDBMS and Apache Kafk...
Solutions for bi-directional integration between Oracle RDBMS and Apache Kafk...Solutions for bi-directional integration between Oracle RDBMS and Apache Kafk...
Solutions for bi-directional integration between Oracle RDBMS and Apache Kafk...
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with Clojure
 

Mehr von MongoDB

MongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
MongoDB SoCal 2020: Migrate Anything* to MongoDB AtlasMongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
MongoDB SoCal 2020: Migrate Anything* to MongoDB AtlasMongoDB
 
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!MongoDB
 
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...MongoDB
 
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDB
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDBMongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDB
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDBMongoDB
 
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...MongoDB
 
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series Data
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series DataMongoDB SoCal 2020: Best Practices for Working with IoT and Time-series Data
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series DataMongoDB
 
MongoDB SoCal 2020: MongoDB Atlas Jump Start
 MongoDB SoCal 2020: MongoDB Atlas Jump Start MongoDB SoCal 2020: MongoDB Atlas Jump Start
MongoDB SoCal 2020: MongoDB Atlas Jump StartMongoDB
 
MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]
MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]
MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]MongoDB
 
MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2
MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2
MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2MongoDB
 
MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...
MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...
MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...MongoDB
 
MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!
MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!
MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!MongoDB
 
MongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your Mindset
MongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your MindsetMongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your Mindset
MongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your MindsetMongoDB
 
MongoDB .local San Francisco 2020: MongoDB Atlas Jumpstart
MongoDB .local San Francisco 2020: MongoDB Atlas JumpstartMongoDB .local San Francisco 2020: MongoDB Atlas Jumpstart
MongoDB .local San Francisco 2020: MongoDB Atlas JumpstartMongoDB
 
MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...
MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...
MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...MongoDB
 
MongoDB .local San Francisco 2020: Aggregation Pipeline Power++
MongoDB .local San Francisco 2020: Aggregation Pipeline Power++MongoDB .local San Francisco 2020: Aggregation Pipeline Power++
MongoDB .local San Francisco 2020: Aggregation Pipeline Power++MongoDB
 
MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...
MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...
MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...MongoDB
 
MongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep Dive
MongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep DiveMongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep Dive
MongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep DiveMongoDB
 
MongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & Golang
MongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & GolangMongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & Golang
MongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & GolangMongoDB
 
MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...
MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...
MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...MongoDB
 
MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...
MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...
MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...MongoDB
 

Mehr von MongoDB (20)

MongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
MongoDB SoCal 2020: Migrate Anything* to MongoDB AtlasMongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
MongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
 
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!
 
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...
 
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDB
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDBMongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDB
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDB
 
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...
 
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series Data
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series DataMongoDB SoCal 2020: Best Practices for Working with IoT and Time-series Data
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series Data
 
MongoDB SoCal 2020: MongoDB Atlas Jump Start
 MongoDB SoCal 2020: MongoDB Atlas Jump Start MongoDB SoCal 2020: MongoDB Atlas Jump Start
MongoDB SoCal 2020: MongoDB Atlas Jump Start
 
MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]
MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]
MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]
 
MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2
MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2
MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2
 
MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...
MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...
MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...
 
MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!
MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!
MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!
 
MongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your Mindset
MongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your MindsetMongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your Mindset
MongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your Mindset
 
MongoDB .local San Francisco 2020: MongoDB Atlas Jumpstart
MongoDB .local San Francisco 2020: MongoDB Atlas JumpstartMongoDB .local San Francisco 2020: MongoDB Atlas Jumpstart
MongoDB .local San Francisco 2020: MongoDB Atlas Jumpstart
 
MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...
MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...
MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...
 
MongoDB .local San Francisco 2020: Aggregation Pipeline Power++
MongoDB .local San Francisco 2020: Aggregation Pipeline Power++MongoDB .local San Francisco 2020: Aggregation Pipeline Power++
MongoDB .local San Francisco 2020: Aggregation Pipeline Power++
 
MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...
MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...
MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...
 
MongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep Dive
MongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep DiveMongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep Dive
MongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep Dive
 
MongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & Golang
MongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & GolangMongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & Golang
MongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & Golang
 
MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...
MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...
MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...
 
MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...
MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...
MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...
 

Kürzlich hochgeladen

Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditSkynet Technologies
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesThousandEyes
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 

Kürzlich hochgeladen (20)

Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance Audit
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 

Getting Started with MongoDB and NodeJS

  • 1. Getting Started With MongoDB and Node.JS Jay Runkel Principal Solutions Architect jay.runkel@mongodb.com @jayrunkel
  • 2. 2
  • 4. 4
  • 5. 5 Perl? What is this 1985?
  • 6. 6 Goal Today • Help you get started with MongoDB and Node.JS • Assumption: – New to both technologies – Programming Experience – Database Experience • Learn from my newbie confusion
  • 7. 7 Agenda 1. Why Node.JS and MongoDB? 2. Find and Insert 3. Node.JS async, event queue, flow control 4. Controlling multiple threads – Bulk insert
  • 10. 10 JavaScript and “JSON” throughout Browser JavaScript Node.JS JavaScriptJSON BSON (JSON) BSON JSON
  • 11. 11 Documents are Rich Data Structures { first_name: ‘Paul’, surname: ‘Miller’, cell: ‘+447557505611’ city: ‘London’, location: [45.123,47.232], Profession: [banking, finance, trader], cars: [ { model: ‘Bentley’, year: 1973, value: 100000, … }, { model: ‘Rolls Royce’, year: 1965, value: 330000, … } ] } Fields can contain an array of sub-documents Fields Typed field values Fields can contain arrays
  • 12. Do More With Your Data MongoDB { first_name: ‘Paul’, surname: ‘Miller’, city: ‘London’, location: [45.123,47.232], cars: [ { model: ‘Bentley’, year: 1973, value: 100000, … }, { model: ‘Rolls Royce’, year: 1965, value: 330000, … } } } Rich Queries Find Paul’s cars Find everybody in London with a car built between 1970 and 1980 Geospatial Find all of the car owners within 5km of Trafalgar Sq. Text Search Find all the cars described as having leather seats Aggregation Calculate the average value of Paul’s car collection Map Reduce What is the ownership pattern of colors by geography over time? (is purple trending up in China?)
  • 14. 14 Sample Data { "_id" : "20160101000000:UA7549", "icao" : "UA7549", "callsign" : "UA7549", "ts" : ISODate("2016-01-01T05:00:00Z"), "events" : { "a" : 1773, "b" : 258, "p" : [50,-60], "s" : 345, "t" : ISODate("2016-01-01T05:00:00Z"), "v" : 299 } }
  • 15. 15 Example: Find Query • Find a flight status entry for United Airlines Flight 1234 – db.data.findOne({"callsign" : "UA7549"}) • Find a aircraft flying at less than 5000 feet – db.data.findOne({"events.a" : {$lt : 5000}}) • Set value of note field – db.data.update({"callsign" : "OY1949"}, {$set : {"note" : "spoke with captain"}})
  • 16. Retrieve One Document in Node.JS The Simple Things Don’t Always Seem Easy
  • 17. 17 The synchronous way var MongoClient = require('mongodb').MongoClient; var db = MongoClient.connect('mongodb://localhost:27017/adsb'); var col = db.collection('data'); var doc = col.findOne({"callsign" : "UA7549"}); console.log("Here is my doc: %j", doc); db.close();
  • 18. 18 The synchronous way var MongoClient = require('mongodb').MongoClient; var db = MongoClient.connect('mongodb://localhost:27017/adsb'); var col = db.collection('data'); var doc = col.findOne({"callsign" : "UA7549"}); console.log("Here is my doc: %j", doc); db.close();
  • 19. 19 It works this way in the mongoshell??? var col = db.getCollection("data"); var doc = col.findOne({"callsign" : "HR9368"}); printjson(doc);
  • 21. 21 Synchronous Programming time Func1 Func1 IO Func1 Func2 Func2 IO Func2
  • 22. 22 Asynchronous Programming time Func1 Func1 IO Func1Func2 Func2 IO Func2 IO Processing runs on separate threads in parallel with main processing thread
  • 23. 23 Callbacks col.findOne({"callsign" : "UA7549"}, function (err, doc) { assert.equal(null, err); console.log("Here is my doc: %j", doc); console.log(”All done!”); • Execute findOne • When it is done, call the callback function • Callback function takes two arguments – err – contains the error message or null – doc – the result of the findOne call • “All Done” will be printed before the “Here is my doc…”
  • 26. 26 Event Queue/Call Stack function find1234 () { col.findOne({_id: 1234}, fo1_cb); find1234(); col.updateMany({color: “blue”}, {$set : {w : 5}}, up1_cb); col.insert({product: 1234, cost: 99}, ins1_cb); console.log(“done”); Call Stack Driver API Callback Queue Event Loop
  • 27. 27 Event Queue/Call Stack function find1234 () { col.findOne({_id: 1234}, fo1_cb); find1234(); col.updateMany({color: “blue”}, {$set : {w : 5}}, up1_cb); col.insert({product: 1234, cost: 99}, ins1_cb); console.log(“done”); Call Stack Driver API Callback Queue Event Loop find1234()
  • 28. 28 Event Queue/Call Stack function find1234 () { col.findOne({_id: 1234}, fo1_cb); find1234(); col.updateMany({color: “blue”}, {$set : {w : 5}}, up1_cb); col.insert({product: 1234, cost: 99}, ins1_cb); console.log(“done”); Call Stack Driver API Callback Queue Event Loop find1234() col.findOne() col.findOne()
  • 29. 29 Event Queue/Call Stack function find1234 () { col.findOne({_id: 1234}, fo1_cb); find1234(); col.updateMany({color: “blue”}, {$set : {w : 5}}, up1_cb); col.insert({product: 1234, cost: 99}, ins1_cb); console.log(“done”); Call Stack Driver API Callback Queue Event Loop col.updateMany() col.findOne() col.updateMany()
  • 30. 30 Event Queue/Call Stack function find1234 () { col.findOne({_id: 1234}, fo1_cb); find1234(); col.updateMany({color: “blue”}, {$set : {w : 5}}, up1_cb); col.insert({product: 1234, cost: 99}, ins1_cb); console.log(“done”); Call Stack Driver API Callback Queue Event Loop col.insert() col.insert() col.updateMany() fo1_cb
  • 31. 31 Event Queue/Call Stack function find1234 () { col.findOne({_id: 1234}, fo1_cb); find1234(); col.updateMany({color: “blue”}, {$set : {w : 5}}, up1_cb); col.insert({product: 1234, cost: 99}, ins1_cb); console.log(“done”); Call Stack Driver API Callback Queue Event Loop console.log() col.updateMany() fo1_cb ins1_cb
  • 32. 32 Event Queue/Call Stack function find1234 () { col.findOne({_id: 1234}, fo1_cb); find1234(); col.updateMany({color: “blue”}, {$set : {w : 5}}, up1_cb); col.insert({product: 1234, cost: 99}, ins1_cb); console.log(“done”); function fo1_cb () {…} Call Stack Driver API Callback Queue Event Loop fo1_cb() col.updateMany() ins1_cb
  • 33. 33 Event Queue/Call Stack Call Stack Driver API Callback Queue Event Loop ins1_cb() up1_cb function find1234 () { col.findOne({_id: 1234}, fo1_cb); find1234(); col.updateMany({color: “blue”}, {$set : {w : 5}}, up1_cb); col.insert({product: 1234, cost: 99}, ins1_cb); console.log(“done”); function ins1_cb () {…}
  • 34. 34 Event Queue/Call Stack Call Stack Driver API Callback Queue Event Loop up1_cb() function find1234 () { col.findOne({_id: 1234}, fo1_cb); find1234(); col.updateMany({color: “blue”}, {$set : {w : 5}}, up1_cb); col.insert({product: 1234, cost: 99}, ins1_cb); console.log(“done”); function up1_cb () {…}
  • 35. Back to the findOne example
  • 36. 36 MongoDB Asynchronous Queries var MongoClient = require('mongodb').MongoClient, assert = require('assert'); MongoClient.connect('mongodb://localhost:27017/adsb', function (err, db) { assert.equal(null, err); var col = db.collection('data'); col.findOne({"callsign" : "UA7549"}, function (err, doc) { assert.equal(null, err); console.log("Here is my doc: %j", doc); db.close(); }); });
  • 37. 37 Asynchronously var MongoClient = require('mongodb').MongoClient, assert = require('assert'); MongoClient.connect('mongodb://localhost:27017/adsb', function (err, db) { assert.equal(null, err); var col = db.collection('data'); col.findOne({"callsign" : "UA7549"}, function (err, doc) { assert.equal(null, err); console.log("Here is my doc: %j", doc); db.close(); }); }); callback
  • 38. 38 Asynchronously var MongoClient = require('mongodb').MongoClient, assert = require('assert'); MongoClient.connect('mongodb://localhost:27017/adsb', function (err, db) { assert.equal(null, err); var col = db.collection('data'); col.findOne({"callsign" : "UA7549"}, function (err, doc) { assert.equal(null, err); console.log("Here is my doc: %j", doc); db.close(); }); }); callback
  • 39. 39 This gets ugly fast var MongoClient = require('mongodb').MongoClient, assert = require('assert'); var db = MongoClient.connect('mongodb://localhost:27017/adsb', function (err, db) { assert.equal(null, err); var col = db.collection('data'); col.findOne({"callsign" : "UA7549"}, function (err, doc) { assert.equal(null, err); console.log("Here is my doc: %j", doc); col.updateOne({"callsign" : "UA7549"}, {$set : {"note" : "Spoke with the pilot"}}, {}, function(err, result) { assert.equal(null, err); console.log("Note updated"); db.close(); }); }); });
  • 40. 40 Nested callbacks - yuck async1(function(input, result1) { async2(function(result2) { async3(function(result3) { async4(function(result4) { async5(function(output) { // do something with output }); }); }); }); })
  • 41. 41 Solutions • Break up into modules • Use a Flow Control library – async – Step • Promises
  • 42. 42 With Flow Control - Step Step ( function connectToMongoDB (err, db) { MongoClient.connect('mongodb:// localhost:27017/adsb', this); }, function findOneDoc(err, db) { if (err) console.log("Connect: %j", err); database = db; collection = db.collection('data'); collection.findOne(csQuery, {}, this); }, function updateDoc(err, doc) { if (err) console.log("Find One: %j", err); console.log("Here is my doc: %j", doc); collection.updateOne(csQuery, {$inc : {"timesViewed" : 1}},{},this); }, function findOneDoc2 (err, result) { if (err) console.log("Update error: %j", err); collection.findOne(csQuery, {}, this); }, function closeConnection(err, doc) { if (err) console.log("FindOne Doc: %j", err); console.log("Note updated: %j", doc); database.close(); } );
  • 43. 43 With Flow Control Step ( function connectToMongoDB (err, db) { MongoClient.connect('mongodb:// localhost:27017/adsb', this); }, function findOneDoc(err, db) { if (err) console.log("Connect: %j", err); database = db; collection = db.collection('data'); collection.findOne(csQuery, {}, this); }, function updateDoc(err, doc) { if (err) console.log("Find One: %j", err); console.log("Here is my doc: %j", doc); collection.updateOne(csQuery, {$inc : {"timesViewed" : 1}},{},this); }, function findOneDoc2 (err, result) { if (err) console.log("Update error: %j", err); collection.findOne(csQuery, {}, this); }, function closeConnection(err, doc) { if (err) console.log("FindOne Doc: %j", err); console.log("Note updated: %j", doc); database.close(); }
  • 44. 44 With Flow Control Step ( function connectToMongoDB (err, db) { MongoClient.connect('mongodb:// localhost:27017/adsb', this); }, function findOneDoc(err, db) { if (err) console.log("Connect: %j", err); database = db; collection = db.collection('data'); collection.findOne(csQuery, {}, this); }, function updateDoc(err, doc) { if (err) console.log("Find One: %j", err); console.log("Here is my doc: %j", doc); collection.updateOne(csQuery, {$inc : {"timesViewed" : 1}},{},this); }, function findOneDoc2 (err, result) { if (err) console.log("Update error: %j", err); collection.findOne(csQuery, {}, this); }, function closeConnection(err, doc) { if (err) console.log("FindOne Doc: %j", err); console.log("Note updated: %j", doc); database.close(); }
  • 45. 45 You can also execute in parallel Step ( function connectToMongoDB (err, db) { MongoClient.connect('mongodb://localhost:27017/adsb', this); }, function executeParallel (err, db) { if (err) console.log("Connect: %j", err); var collection = db.collection('data'); database = db; collection.findOne(csQuery, {}, this.parallel()); collection.updateOne(csQuery, {$inc : {"timesViewed" : 1}}, {}, this.parallel()); collection.findOne(csQuery, {}, this.parallel()); }, function closeConnection(err, doc1, upResult, doc2) { if (err) console.log("Error: %j", err); console.log("Here is doc1: %j", doc1); console.log("Incremented: %j", upResult); console.log("Here is doc2: %j", doc2); database.close(); } );
  • 46. How do you deal with multiple find results?
  • 47. 47 Find Many - Cursor • This works in the MongoShell var col = db.getCollection("data"); var cursor = col.find({"events.a" : {$gt : 5000}}); while (cursor.hasNext()) { printjson(cursor.next()); }
  • 48. 48 Find Many - Cursor • This works in the MongoShell var col = db.getCollection("data"); var cursor = col.find({"events.a" : {$gt : 5000}}); while (cursor.hasNext()) { printjson(cursor.next()); } • It does not work in Node.JS • The MongoDB driver retrieves documents in batches from MongoDB – Retrieving a new batch is asynchronous
  • 49. 49 Find Many - Streams MongoClient.connect("mongodb://localhost:27017/adsb", function (err, db) { var col = db.collection('data') var stream = col.find({"events.a" : {$gt : 5000}}).stream(); stream.on('data', function(doc) { console.log("Doc: %j", doc); }); stream.on('error', function (doc) { console.log("Query failed: %j", doc); }); stream.on('end', function() { console.log("All data retrieved."); db.close(); }); });
  • 50. 50 Find Many - Streams MongoClient.connect("mongodb://localhost:27017/adsb", function (err, db) { var col = db.collection('data') var stream = col.find({"events.a" : {$gt : 5000}}).stream(); stream.on('data', function(doc) { console.log("Doc: %j", doc); }); stream.on('error', function (doc) { console.log("Query failed: %j", doc); }); stream.on('end', function() { console.log("All data retrieved."); db.close(); }); }); ‘data’ callback invoked for each document
  • 51. 51 What about insert? MongoClient.connect('mongodb://localhost:27017/adsb', function (err, db) { assert.equal(null, err); var col = db.collection('data'); col.insert({x: 1, y: 2, z: 3}, {}, function (err, result) { assert.equal(null, err); console.log("Insert Complete"); db.close(); }); });
  • 52. 52 What if I have to insert 100M documents? MongoClient.connect('mongodb://localhost:27017/adsb', function (err, db) { assert.equal(null, err); var col = db.collection('data'); for (i = 1; i <= 100000000; i++) { col.insert({x: i, y: 2, z: 3}, {}, function (err, result) { assert.equal(null, err); console.log("Insert Complete"); }); } }); Let’s insert all 100,000,000 in parallel!!!!
  • 53. 53 What if I have to insert 100M documents? MongoClient.connect('mongodb://localhost:27017/adsb', function (err, db) { assert.equal(null, err); var col = db.collection('data'); for (i = 1; i <= 100000000; i++) { col.insert({x: i, y: 2, z: 3}, {}, function (err, result) { assert.equal(null, err); console.log("Insert Complete"); db.close(); }); } }); FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
  • 54. 54 Event Queue/Call Stack for (i = 1; i <= 100000000; i++) { col.insert({x: i, y: 2, z: 3}, {}, function (err, result) { assert.equal(null, err); console.log("Insert C…"); }); } Call Stack Driver API Callback Queue Event Loop
  • 55. 55 Event Queue/Call Stack for (i = 1; i <= 100000000; i++) { col.insert({x: i, y: 2, z: 3}, {}, function (err, result) { assert.equal(null, err); console.log("Insert C…"); db.close(); }); Call Stack Driver API Callback Queue Event Loop col.insert() col.insert() col.insert() col.insert() col.insert() col.insert() col.insert() col.insert() col.insert()
  • 56. 56 Event Queue/Call Stack for (i = 1; i <= 100000000; i++) { col.insert({x: i, y: 2, z: 3}, {}, function (err, result) { assert.equal(null, err); console.log("Insert C…"); db.close(); }); Call Stack Driver API Callback Queue Event Loop col.insert() col.insert() col.insert() col.insert() col.insert() col.insert() col.insert() col.insert() col.insert() FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
  • 57. 57 Let’s try 5 at a time var DOCS_TO_INSERT = 1000; var numInsertsRunning = 0; // number of insert threads var insertCount = 0; // number of documents inserted so far MongoClient.connect('mongodb://localhost:27017/adsb', function (err, db) { assert.equal(null, err); var col = db.collection('data'); for (i = 0; i < 5; i++) { ++numInsertsRunning; insertDocument(db, col, ++insertCount, i, function (err, result) { console.log("All ", DOCS_TO_INSERT, " documents inserted."); db.close(); }); } });
  • 58. 58 insertDocument function function insertDocument (db, col, docNum, threadNum, callback) { col.insert({x: ++insertCount, y: 2, z: 3}, {}, function (err, result) { assert.equal(null, err); console.log("Thread: ", threadNum, " inserted doc: ", docNum, "."); if (insertCount < DOCS_TO_INSERT) insertDocument(db, col, ++insertCount, threadNum, callback); else if (numInsertsRunning == 1) { numInsertsRunning--; callback(null, true); } else numInsertsRunning--; }); }
  • 59. 59 InsertDocument Callback Logic col.insert({x: ++insertCount, y: 2, z: 3}, function (err, result) { } Have all the documents been inserted? Call insertDocument again Are other inserts still running? Do nothing & decrement running thread count All inserts done Call the original callback Yes Yes No No
  • 60. 60 Bulk Inserts • The previous example was for illustrative purposes • MongoDB provides a buik write API that provides better performance for bulk writes • The bulk write API batches up writes – Batch writes with a single acknowledgement • Use collection.bulkWrite • Improve performance using multiple bulkWrite threads – Previous example will be identical – Replace collection.insert with collection.bulkWrite
  • 61. 61 Another word of caution • All my examples established a MongoDB connection and then closed it – This was for illustrative purposes • Don’t continuously open and close MongoDB connections. • Open a connection once once – Use that connection through the life of the program – Close it at the end
  • 62. 62 Summary • Asynchronous vs synchronous programming • Call stack, event loop, driver API • Flow control • Find, insert, update examples • Managing multiple parallel threads – bulk insert example • Learn from my mistakes and misconceptions