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

Post on 01-Apr-2015

231 views 4 download

transcript

MongoAn alternative database system

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

What is Mongo?

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

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

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

Implementation of Mongo

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

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

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()

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!

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

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

Documents

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

If you are using Windows

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

You should get this

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/

RockMongo is perhaps the best

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.