Mongo An alternative database system. Installing Mongo We must install both the Mongo database and...

17
Mongo An alternative database system

Transcript of Mongo An alternative database system. Installing Mongo We must install both the Mongo database and...

Page 1: Mongo An alternative database system. Installing Mongo We must install both the Mongo database and at least one GUI for managing Mongo See .

MongoAn alternative database system

Page 2: Mongo An alternative database system. Installing Mongo We must install both the Mongo database and at least one GUI for managing Mongo See .

Installing Mongo

• We must install both the Mongo database and at least one GUI for managing Mongo

• See http://docs.mongodb.org/manual/installation • See http://www.mongodb.org/display/DOCS/Admin+UIs

Page 3: Mongo An alternative database system. Installing Mongo We must install both the Mongo database and at least one GUI for managing Mongo See .

What is Mongo?

• Document based • Focuses on clusters for extremely large scaling • Supports nested documents• Uses JavaScript for queries• No schema)

Page 4: Mongo An alternative database system. Installing Mongo We must install both the Mongo database and at least one GUI for managing Mongo See .

Basic Mongo concepts

• A database consists of collections• Which is more or less a table

• Collections are made up of documents • A lot like rows

• A document is made up of fields• A lot like columns

• There are also indices• There are also cursors

Page 5: Mongo An alternative database system. Installing Mongo We must install both the Mongo database and at least one GUI for managing Mongo See .

Mongo goals

• “Horizontal” scaling – • i.e., the cloud & simple servers• And no joins, effectively, pre-computed joins• Anti-normalization

• Fast• Avoid bottleneck of centralized schema• Near real-time data access• High availability

Page 6: Mongo An alternative database system. Installing Mongo We must install both the Mongo database and at least one GUI for managing Mongo See .

Implementation of Mongo

• C++• Heavy use of memory caching for read and write-through• Distributes by sharding

Page 7: Mongo An alternative database system. Installing Mongo We must install both the Mongo database and at least one GUI for managing Mongo See .

Applications of Mongo

• Medical records and other large document systems• Read heavy environments like analytics and mining• Partnered with relational databases• Relational for live data• Mongo for huge largely read only archives

• Online applications• Massively wide e-commerce

Page 8: Mongo An alternative database system. Installing Mongo We must install both the Mongo database and at least one GUI for managing Mongo See .

Using Mongo

• In bin folder• mongod for database• mongo for shell

• For data, it needs a directory called data on c: and a directory called db within data

• Commands• Global, like help• Db-specific, like db.x, where x is the collection• Db.x.help()

Page 9: Mongo An alternative database system. Installing Mongo We must install both the Mongo database and at least one GUI for managing Mongo See .

Tutorial from mongodb.pdf: The Little MongoDB Book

• Go to: http://openmymind.net/mongodb.pdf• First command: use learn• Second command: db.unicorns.insert({name: ‘Aurora’,

gender: ‘f’, weight: 450})• In other words, we can create a db and a collection

simply by saying they exist – no schema!

Page 10: Mongo An alternative database system. Installing Mongo We must install both the Mongo database and at least one GUI for managing Mongo See .

Query selectors

• Similar to an SQL program• Used for finding, counting, updating, and removing docs

from collections• {} is the null search and matches all documents• We could run: {gender:’f’}• {field1: value1, field2: value2} creates an ‘and’ operation• Also, less than, greater than, etc. (e.g., $gt)• $exists, $or

Page 11: Mongo An alternative database system. Installing Mongo We must install both the Mongo database and at least one GUI for managing Mongo See .

Updating data

• db.unicorns.update({name: ‘ro’}, {weight: 590})• Finds unicorn with that name and updates its weight

• Can also find and update records according to the keys mongo has assigned

• Note: mongo supports arrays as document fields

Page 12: Mongo An alternative database system. Installing Mongo We must install both the Mongo database and at least one GUI for managing Mongo See .

Documents

• Nested documents are supported• DBRef allows documents to reference each other• For the future? Full text search• Map reduce

Page 13: Mongo An alternative database system. Installing Mongo We must install both the Mongo database and at least one GUI for managing Mongo See .

If you are using Windows

• Go to http://mongovue.com• Install it• Run it…

Page 14: Mongo An alternative database system. Installing Mongo We must install both the Mongo database and at least one GUI for managing Mongo See .

You should get this

Page 15: Mongo An alternative database system. Installing Mongo We must install both the Mongo database and at least one GUI for managing Mongo See .

Other GUIs that are easy to install

• MongoVision (web based): http://code.google.com/p/mongo-vision/

• PHPMoAdmin (web based): http://www.phpmoadmin.com/ – this one is ugly, though!

• RockMongo (web based): http://rockmongo.com/

Page 16: Mongo An alternative database system. Installing Mongo We must install both the Mongo database and at least one GUI for managing Mongo See .

RockMongo is perhaps the best

Page 17: Mongo An alternative database system. Installing Mongo We must install both the Mongo database and at least one GUI for managing Mongo See .

Mongo tutorial: Assignment 8: Due Dec. 4

• Read the 33 page book• Follow the entire tutorial• Send an “I did it.” message for homework 8• Include your final document database (“db”) as a zipped

attachment• Include a screen snapshot of the GUI you used. (You can

do the project easily without a GUI, but it’s a good idea to get an idea of how they work.)

• Important: this material will be on the final.