3. AGENDA
Day 1: Full theory(MEHN) and mongodb practical
Day 2: Full practical developing code from scratch MEHN
Day3:
Brief explanation on How complex code is, if we doesn't use
handlebars JS in our app
some theory on popular java scripts and demo on vanilla
script.
23. INSERT VS
INSERTONE
• Insert
(deprecated)
• insertOne
• insertMany
MongoDB's update() and save() methods
are used to update document into a collection.
Update vs save
Update: changes an existing document found by
your find-parameters and does nothing when no
such document exist (unless you use the upsert =
true option).
Save: doesn't allow any find-parameters. It checks if
there is a document with the same _id as the one
you save exists. When it exists, it replaces it. When
no such document exists, it inserts the document as
a new one.
25. FEATURES
• Document-Oriented storege
• Full Index Support
• Replication & High
Availability
• Auto-Sharding
• Querying
• Fast In-Place Updates
• Map/Reduce
25
Agile
Scalable
Auto-Sharding ?
26. INSTALLATION• https://www.mongodb.com/download-center#enterprise
• Two ways to start
• 1: Normal way
• mongodb –dbpath D:mongodatadb
• mongo
• 2: Background as a service
Command1: Mongod --directoryperdb –dbpath D:mongodatadb
--logpath D:mongologmongo.log –logappend –rest --install
Command 2: Net start MongoDB
27. LIVE DEMO IN MONGO CLIENT
•Mongodb major developer Operations
Better will do this in practical session slot
28. CONNECT MONGODB TO OUR APPvar url = "mongodb://localhost:27017/database-name";
var MongoClient =require('mongodb').MongoClient;
List All:
MongoClient.connect(url, function(err, db) {
var result = [];
if (err) throw err;
var cursor =db.collection('mehn').find({});
cursor.forEach(function(doc, err) {
result.push(doc);
}, function() {
db.close();
});
});
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44. OTHER WAYS…
var express = require('express');
var app = express();
var server = app.listen(8085, function () {
var host = server.address().address
var port = server.address().port
console.log("Example app listening at http://%s:%s", host, port)
})
45.
46.
47.
48.
49. "plugins" known as middleware.
https://stephensugden.com/middleware_guide/
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61. EXPRESS-HANDLEBARS
var express = require('express');
var path = require('path');
var app = express();
// View Engine
var exphbs = require('express-handlebars');
app.set('views', path.join(__dirname, 'views'));
app.engine('handlebars',exphbs({defaultLayout:'layout'}));
app.set('view engine', 'handlebars');
//end view Engine for handlebars
65. THANK YOU.
Day2 Practical Demo
From the scratch in front of you
CRUD Operation
Pre – requisites:
Nodejs v8
Mongo dB
Frameworks:
Express
HandlebarsJS
Editor's Notes
Huge quantity of data => Distributed systems => expensive joins =>
New fields, new demands (graphs) =>
Different data strucutres:
Simplier or more specific
2009: Initial release
At now: version 2.2.3
Create
The field name _id is reserved for use as a primary key; its value must be unique in the collection, is immutable, and may be of any type other than an array.
The field names cannot start with the $ character.
The field names cannot contain the . character.
Create with save
If the <document> argument does not contain the _id field or contains an _id field with a value not in the collection, the save() method performs an insert of the document.
Otherwise, the save() method performs an update.
sds