Introduction to MongoDB (Version 1)

465 views

Published on

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Introduction to MongoDB (Version 1)

  1. 1. MongoDB Introduction to MongoDB
  2. 2. 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
  3. 3. CAP Theorem
  4. 4. Database Objects ● ● ● ● Database Collection Document Index
  5. 5. Map it! MongoDB SQL Server Database Database Collections Tables Document Row
  6. 6. What is the document here? { { _id : 1, _id : 1, name : “Sam Walton”, name : “Sam Walton”, age : 74, age : 74, company : company : { [ name : ”walmart” “Walmart”,”Walton Five” } ] } } In MongoDB we use JSON to represent our data. Document is more like a record in Relational Databases.
  7. 7. Data Type ObjectID - 12bytes Number String Boolean Date/Time null
  8. 8. Designing Denormalizing is ok? Foreign keys? NO Then How? Is it same for all NoSQL databases?
  9. 9. DEMO
  10. 10. Indexing Can I create Secondary indexes? Lots of indexes ? NO? Full text search ?
  11. 11. Authentication By default authentication is turned off in MongoDB. (So we have to turn it on!) Users/Roles SSL Schema Injection
  12. 12. WriteConcern Journaling (j) Basically log mechanism for durability w option You 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.
  13. 13. Anything else? SlaveOk Sharding
  14. 14. Sample C# Code using 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);
  15. 15. Connection String http://docs.mongodb. org/manual/reference/connection-string/ mongodb://sysop:moon@example1.com,example2.com,example3.com/?w=2&wtimeoutMS=2000
  16. 16. DEMO
  17. 17. Thank you!

×