Dineesha Suraweera
What is mongoDB? Open Source Document Oriented database Cross- Platform No - SQL 1
Published as GNU Affero General Public License and the Apache License Developed by 10gen in 2007 Published as GNU Affero General Public License and the Apache License
Document Oriented vs Relational Databases Schema less Structure of a single object is clear No complex joins Deep query-ability Ease of scale-out Conversion / mapping of application objects to database objects not needed Uses internal memory for storing the working set, enabling faster access of data
RDBMS mongoDB Database Table Collection Tuple/Row Document column Field Table Join Embedded Documents Primary Key Primary Key (Default key _id provided by mongodb itself)
MongoDB Architecture
Features Ad hoc queries Indexing Replication File storage Aggregation Sharding Capped collections
Horizontally Scalable Architecture
Sharding
Replication
Document Storage Document are stored in BSON(Binary JSON) BSON - binary serialization of json like objects. Any valid JSON can easily imported and queried. MongoDB understand JSON natively.
MongoDB Storage Engines
db – show currently selected database. show dbs – output database list Create Database use DATABASE_NAME db – show currently selected database. show dbs – output database list
db.createCollection(name, options) "mycol", { capped : true, autoIndexID : true, Size : 6142800, max : 10000 } )
db.COLLECTION_NAME.insert(document) db.mycol.insert({ _id: ObjectId(7df78ad8902c), title: 'MongoDB Overview', description: 'MongoDB is no sql database', tags: ['mongodb', 'database', 'NoSQL'], likes: 100 })
Sample Document { _id: ObjectId(7df78ad8902c) title: 'MongoDB Overview', description: 'MongoDB is no sql database', tags: ['mongodb', 'database', 'NoSQL'], likes: 100, comments: [ user:'user1', message: 'My first comment', dateCreated: new Date(2016,1,20,2,15), like: 0 }, user:'user2', message: 'My second comments', dateCreated: new Date(2016,1,25,7,45), like: 5 } ]
db.COLLECTION_NAME.find() Query Document db.COLLECTION_NAME.find() (formatted way) db.COLLECTION_NAME.find().pretty()
db.COLLECTION_NAME.ensureIndex({KEY:1}) Indexing db.COLLECTION_NAME.ensureIndex({KEY:1}) db.mycol.ensureIndex({"title":1,"description":-1})
Demonstration
Non-Functional Features Easy readability High performance High availability Easy scalability Aggregation Stores data as documents or objects (everyone works with objects)
Disadvantages or less good at ???? High transactions Problems that require SQL
Other No-SQL databases Cassandra Accumulo Cloudata HPCC ConcourseDB Druid SpliceMachine
Big Data Where to use ??? Content Management and Delivery Mobile and Social Infrastructure User Data Management Data Hub
Adobe Ebay LinkedIn McAfee SAP Yandex Users of MongoDB Adobe Ebay LinkedIn McAfee SAP Yandex
Thank You!