"MongoDB is a document database that provides high performance, high availability, and easy scalability. Document Database. Documents (objects) map nicely to programming language data types. Embedded documents and arrays reduce need for joins."
.... I'm sorry..WHAT?!
MongoDB is an open-source document database, and leading NoSQL database.
$ brew update
$ brew install mongodb
$ mongod --dbpath *path to data folder*
Suppose a client needs a database design for his blog website and see the differences between RDBMS and MongoDB schema design. Website has the following requirements.
{ _id: POST_ID title: TITLE_OF_POST, description: POST_DESCRIPTION, by: POST_BY, url: URL_OF_POST, tags: [TAG1, TAG2, TAG3], likes: TOTAL_LIKES, comments: [ { user:'COMMENT_BY', message: TEXT, dateCreated: DATE_TIME, like: LIKES }, { user:'COMMENT_BY', message: TEXT, dateCreated: DATE_TIME, like: LIKES } ] }
Basic commands to get you started!
>use mydb switched to db mydb
>show dbs local 0.78125GB test 0.23012GB >show collections mycol mycollection system.indexes
>db.dropDatabase(); >{ "dropped" : "mydb", "ok" : 1 }
More commands..
>db.createCollection("mycollection") { "ok" : 1 } >db.createCollection("mycol", { capped : true, autoIndexID : true, size : 6142800, max : 10000 } ) { "ok" : 1 }
>db.mycollection.drop() true
>db.mycol.insert({ _id: ObjectId(7df78ad8902c), title: 'MongoDB Overview', description: 'MongoDB is no sql database', by: 'IOLAB 2014', url: 'http://courses.ischool.berkeley.edu/i290ta/f14/', tags: ['mongodb', 'database', 'NoSQL'], likes: 100 })
And more commands..
>db.mycol.find({"by":"IOLAB 2014","title": "MongoDB Overview"}).pretty() { "_id": ObjectId(7df78ad8902c), "title": "MongoDB Overview", "description": "MongoDB is no sql database", "by": "IOLAB 2014", "url": "http://courses.ischool.berkeley.edu/i290ta/f14/", "tags": ["mongodb", "database", "NoSQL"], "likes": "100" }
>db.mycol.find({$or:[{"by":"IOLAB 2014"},{"title": "MongoDB Overview"}]}).pretty() { "_id": ObjectId(7df78ad8902c), "title": "MongoDB Overview", "description": "MongoDB is no sql database", "by": "IOLAB 2014", "url": "http://courses.ischool.berkeley.edu/i290ta/f14/", "tags": ["mongodb", "database", "NoSQL"], "likes": "100" }