Presentation on MongoDB and Node.JS. We describe how to do basic CRUD operations (insert, remove, update, find) how to aggregate using node.js. We also discuss a bit of Meteor, MEAN Stack and other ODMs and projects on Javascript and MongoDB
8. 8
MongoDB + Javascript
• MongoDB Shell
– JS interperter
• MongoDB MapReduce
– Runs on top of V8
– Map and Reduce functions are JS functions
• Native support for Node.js
– One of the most used Drivers out there!
– https://www.npmjs.com/package/mongodb
22. boot up MongoDB Server
$ mkdir ~/firstappdb
$ mongod --dbpath ~/firstappdb
23. boot up MongoDB Server
$ mkdir ~/firstappdb
$ mongod --dbpath ~/firstappdb --auth
--keyfile ~/n.pem
https://www.mongodb.com/products/mongodb-enterprise-advanced
24. boot up MongoDB Server
$ mkdir ~/firstappdb
$ mongod --dbpath ~/firstappdb --auth
--keyfile ~/n.pem
https://www.mongodb.com/products/mongodb-enterprise-advanced
25. var MongoClient = require('mongodb').MongoClient,
assert = require('assert');
Connect
26. var MongoClient = require('mongodb').MongoClient,
assert = require('assert');
//connection uri
var uri = "mongodb://localhost:27017/firstapp"
Connect
27. var MongoClient = require('mongodb').MongoClient,
assert = require('assert');
//connection uri
var uri = "mongodb://localhost:27017/firstapp"
//connect to MongoDB
MongoClient.connect(uri, function(err, db){
assert.equal(null, err);
console.log("Connected correctly to server");
db.close();
});
Connect
28. 28
Connection Pooling
• No traditional Pooling mechanism
– Single thread process
• Sockets to pipeline operations
• Failover
– Buffering up operations
– bufferMaxEntries
– numberOfRetries
– retryMiliSeconds
http://mongodb.github.io/node-mongodb-native/2.0/api/Db.html
71. Simple Mongoose
var mongoose = require('mongoose'), assert =
require('assert')
var Schema = mongoose.Schema;
//define a schema
var userSchema = new Schema({ name: String, age:
Number})
//create static members
userSchema.statics.findByName = function( name, cb){
return this.find( {"name": name}, cb);
}
…
72. Simple Mongoose
…
//generate a model
var User = mongoose.model('User', userSchema);
//initiate the new user, validates the given arguments
var u1 = User({name:"Many Delgado", age:14});
//just save it
u1.save(function(err){
assert.equal(null, err);
});
76. Express is a minimal and flexible Node.js web
application framework that provides a robust
set of features for web and mobile
applications.
77. AngularJS lets you extend HTML vocabulary
for your application. The resulting
environment is extraordinarily expressive,
readable, and quick to develop
78. Building your first app with MongoDB: Creating
a RESTAPI using the MEAN Stack
https://www.mongodb.com/blog/post/building-
your-first-application-mongodb-creating-rest-
api-using-mean-stack-part-1
84. 84
What we talked about today…
• Node.js is a very productive language
– Our driver is highly adopted
– Updated
– Fully compatible
• CRUD Operations
– Insert, Update, Remove, Delete
• Write Concerns
– Flexible to write
• Read Preferences
– Flexible to read
• Aggregation Framework
– Analytics at your fingertips
86. 86
Where to next?
• Questions on the driver:
– https://groups.google.com/forum/#!forum/node-mongodb-native
• Issues:
– https://jira.mongodb.org/browse/NODE/?
selectedTab=com.atlassian.jira.jira-projects-plugin:summary-
panel
• Tutorial:
– http://mongodb.github.io/node-mongodb-native/2.0/
• Todays code:
– https://github.com/nleite/firstappnodejs
• Other:
– http://www.mongodb.com/norberto
87. 87
For More Information
Resource Location
Case Studies mongodb.com/customers
Presentations mongodb.com/presentations
Free Online Training education.mongodb.com
Webinars and Events mongodb.com/events
Documentation docs.mongodb.org
MongoDB Downloads mongodb.com/download
Additional Info info@mongodb.com
Blog blog.mongodb.com