Introduction to MongoDB (Version 1)

17
MongoDB Introduction to MongoDB

Transcript of Introduction to MongoDB (Version 1)

Page 1: Introduction to MongoDB (Version 1)

MongoDBIntroduction to MongoDB

Page 2: Introduction to MongoDB (Version 1)

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)

CAP Theorem

Page 4: Introduction to MongoDB (Version 1)

Database Objects

● Database● Collection● Document● Index

Page 5: Introduction to MongoDB (Version 1)

Map it!

MongoDB SQL Server

Database Database

Collections Tables

Document Row

Page 6: Introduction to MongoDB (Version 1)

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)

Data Type

ObjectID - 12bytesNumberStringBooleanDate/Timenull

Page 8: Introduction to MongoDB (Version 1)

Designing

Denormalizing is ok?

Foreign keys? NOThen How?

Is it same for all NoSQL databases?

Page 9: Introduction to MongoDB (Version 1)

DEMO

Page 10: Introduction to MongoDB (Version 1)

Indexing

Can I create Secondary indexes?

Lots of indexes ? NO?

Full text search ?

Page 11: Introduction to MongoDB (Version 1)

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)

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)

Anything else?

SlaveOk

Sharding

Page 14: Introduction to MongoDB (Version 1)

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)

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)

DEMO

Page 17: Introduction to MongoDB (Version 1)

Thank you!