Introduction to MongoDB (Version 1)
-
Upload
dedunu-dhananjaya -
Category
Technology
-
view
222 -
download
0
Transcript of Introduction to MongoDB (Version 1)
![Page 1: Introduction to MongoDB (Version 1)](https://reader036.fdocuments.net/reader036/viewer/2022073116/554f8f7bb4c9052a518b52dd/html5/thumbnails/1.jpg)
MongoDBIntroduction to MongoDB
![Page 2: Introduction to MongoDB (Version 1)](https://reader036.fdocuments.net/reader036/viewer/2022073116/554f8f7bb4c9052a518b52dd/html5/thumbnails/2.jpg)
What is NoSQL?
A NoSQL database provides a mechanism for storage and retrieval of data that uses looser consistency models than traditional relational databases. -Wikipedia
![Page 3: Introduction to MongoDB (Version 1)](https://reader036.fdocuments.net/reader036/viewer/2022073116/554f8f7bb4c9052a518b52dd/html5/thumbnails/3.jpg)
CAP Theorem
![Page 4: Introduction to MongoDB (Version 1)](https://reader036.fdocuments.net/reader036/viewer/2022073116/554f8f7bb4c9052a518b52dd/html5/thumbnails/4.jpg)
Database Objects
● Database● Collection● Document● Index
![Page 5: Introduction to MongoDB (Version 1)](https://reader036.fdocuments.net/reader036/viewer/2022073116/554f8f7bb4c9052a518b52dd/html5/thumbnails/5.jpg)
Map it!
MongoDB SQL Server
Database Database
Collections Tables
Document Row
![Page 6: Introduction to MongoDB (Version 1)](https://reader036.fdocuments.net/reader036/viewer/2022073116/554f8f7bb4c9052a518b52dd/html5/thumbnails/6.jpg)
What is the document here?{
_id : 1,name : “Sam Walton”,age : 74,company :
[“Walmart”,”Walton Five”]
}
In MongoDB we use JSON to represent our data. Document is more like a record in Relational Databases.
{_id : 1,name : “Sam Walton”,age : 74,company :
{ name : ”walmart”}
}
![Page 7: Introduction to MongoDB (Version 1)](https://reader036.fdocuments.net/reader036/viewer/2022073116/554f8f7bb4c9052a518b52dd/html5/thumbnails/7.jpg)
Data Type
ObjectID - 12bytesNumberStringBooleanDate/Timenull
![Page 8: Introduction to MongoDB (Version 1)](https://reader036.fdocuments.net/reader036/viewer/2022073116/554f8f7bb4c9052a518b52dd/html5/thumbnails/8.jpg)
Designing
Denormalizing is ok?
Foreign keys? NOThen How?
Is it same for all NoSQL databases?
![Page 9: Introduction to MongoDB (Version 1)](https://reader036.fdocuments.net/reader036/viewer/2022073116/554f8f7bb4c9052a518b52dd/html5/thumbnails/9.jpg)
DEMO
![Page 10: Introduction to MongoDB (Version 1)](https://reader036.fdocuments.net/reader036/viewer/2022073116/554f8f7bb4c9052a518b52dd/html5/thumbnails/10.jpg)
Indexing
Can I create Secondary indexes?
Lots of indexes ? NO?
Full text search ?
![Page 11: Introduction to MongoDB (Version 1)](https://reader036.fdocuments.net/reader036/viewer/2022073116/554f8f7bb4c9052a518b52dd/html5/thumbnails/11.jpg)
Authentication
By default authentication is turned off in MongoDB. (So we have to turn it on!)
Users/Roles
SSL
Schema Injection
![Page 12: Introduction to MongoDB (Version 1)](https://reader036.fdocuments.net/reader036/viewer/2022073116/554f8f7bb4c9052a518b52dd/html5/thumbnails/12.jpg)
WriteConcern
Journaling (j)Basically log mechanism for durability
w optionYou can have -1,0,1... for this value. majority, n, tags-1 - No errors will be returned.0 - Server error will not be returned. But
Network,Socket errors would be reported.
![Page 13: Introduction to MongoDB (Version 1)](https://reader036.fdocuments.net/reader036/viewer/2022073116/554f8f7bb4c9052a518b52dd/html5/thumbnails/13.jpg)
Anything else?
SlaveOk
Sharding
![Page 14: Introduction to MongoDB (Version 1)](https://reader036.fdocuments.net/reader036/viewer/2022073116/554f8f7bb4c9052a518b52dd/html5/thumbnails/14.jpg)
Sample C# Codeusing MongoDB.Bson;using MongoDB.Driver;
String connectionString = "mongodb://localhost";MongoClient client = new MongoClient(connectionString);
MongoDatabase database = server.GetDatabase("blogging");
MongoCollection collection = database.GetCollection("blogs");
BsonDocument document = new BsonDocument();
document.Add("name", “Walton”);
document.Add("age", 74);
collection.Insert(document);
![Page 15: Introduction to MongoDB (Version 1)](https://reader036.fdocuments.net/reader036/viewer/2022073116/554f8f7bb4c9052a518b52dd/html5/thumbnails/15.jpg)
Connection String
http://docs.mongodb.org/manual/reference/connection-string/
mongodb://sysop:[email protected],example2.com,example3.com/?w=2&wtimeoutMS=2000
![Page 16: Introduction to MongoDB (Version 1)](https://reader036.fdocuments.net/reader036/viewer/2022073116/554f8f7bb4c9052a518b52dd/html5/thumbnails/16.jpg)
DEMO
![Page 17: Introduction to MongoDB (Version 1)](https://reader036.fdocuments.net/reader036/viewer/2022073116/554f8f7bb4c9052a518b52dd/html5/thumbnails/17.jpg)
Thank you!