Top Banner
by Klevis Mino
19

Klevis Mino: MongoDB

Sep 03, 2014

Download

Technology

Carlo Vaccari

Project by Klevis Mino
Course "Innovation and New Technologies" - University of Camerino
(teacher C. Vaccari)
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Klevis Mino: MongoDB

by Klevis Mino

Page 2: Klevis Mino: MongoDB

What is NoSQL?NoSQL featuresNoSQL database typesWhat is MongoDB?Who uses MongoDB? Installation and RunningDocuments and CollectionsMongoDB features

Querying Indexing Replication Load balancing File storage Aggregation

Page 3: Klevis Mino: MongoDB

What is NoSQL?

Definition: “Next generation databases mostly addressing some of the points: being non-relational, distributed, open source and horizontally scalable… schema-free, easy replication support, simple API, eventually consistent, huge amount of data…”

- nosql-database.org

Page 4: Klevis Mino: MongoDB

What is NoSQL?

Definition: “Next generation databases mostly addressing some of the points: being non-relational, distributed, open source and horizontally scalable… schema-free, easy replication support, simple API, eventually consistent, huge amount of data…”

- nosql-database.org

NoSQL database types• Document databases• Graph stores• Key-value stores• Wide-column stores

Page 5: Klevis Mino: MongoDB

What is MongoDB?Definition: “MongoDB (from "humongous") is an open-source document database that provides high performance, high availability, and automatic scaling.”

- mongodb.org

Key featuresHigh performanceHigh availabilityAutomatic scaling

Page 6: Klevis Mino: MongoDB

Who uses MongoDB?

Page 7: Klevis Mino: MongoDB

InstallationDownload MongoDB from mongodb.orgExtract to local disk C:\Rename the extracted folder to “mongodb”

Running MongoDBCreate a folder to store files, C:\data\dbTo start MongoDB with Command Prompt: C:\

mongodb\bin\mongod.exeOpen another CMD and execute: C:\

monogodb\bin\mongo.exe

Page 8: Klevis Mino: MongoDB

Documents and CollectionsA document is the basic unit of data.

Documents are stored on disk in BSON (binary JSON) serialization format.

{name: “klevis”, field: valueage: 21, field: valuestatus: “A”, field: valuegroups: [ “news”, “sports” ] field: value

}

Page 9: Klevis Mino: MongoDB

Documents and CollectionsA collection is a group of documents

(equivalent to a table in a RDBMS). A collection exists within a single database.

Page 10: Klevis Mino: MongoDB

MongoDB features

Querying IndexingReplicationLoad balancingFile storageAggregationServer-side JavaScrip executionCapped collections

Page 11: Klevis Mino: MongoDB

QueryingMongoDB supports search by field, range queries, regular expression searches.

Page 12: Klevis Mino: MongoDB

QueryingThe find() method returns a cursor to the resultsTo display all the results:var c = db.testData.find()while ( c.hasNext() ) printjson( c.next() )

To limit the number of resultsdb.testData.find().limit(3)To print a certain resultprintjson( c [1] )Searching for certain values of a fielddb.testData.find({x:3})

Page 13: Klevis Mino: MongoDB

QueryingProjectionsUsed to return or exclude certain fields of matching documents in a query.

Page 14: Klevis Mino: MongoDB

IndexingIndexes provide high performance read operations for frequently used queries. Indexes are special data structures that store a small portion of the collection’s data set in an easy to traverse form.

Page 15: Klevis Mino: MongoDB

ReplicationMongoDB provides high availability and increased throughput with replica sets. A replica set consists of two or more copies of the data. Each replica may act in the role of primary or secondary replica at any time.

Page 16: Klevis Mino: MongoDB

Load balancingMongoDB scales horizontally using sharding. The user chooses a shard key, which determines how the data in a collection will be distributed. The data is split into ranges and distributed across multiple shards. MongoDB can run over multiple servers, balancing the load and/or duplicating data to keep the system up and running in case of hardware failure. Automatic configuration is easy to deploy, and new machines can be added to a running database.

Page 17: Klevis Mino: MongoDB

File storageMongoDB can be used as a file system, taking advantage of load balancing and data replication features over multiple machines for storing files.The function GriFS is included with MongoDB drivers and available with no difficulty for development languages. MongoDB exposes functions for file manipulation and content to developers. In a multi-machine MongoDB system, files can be distributed and copied multiple times between machines transparently, thus effectively creating a load-balanced and fault-tolerant system.

Page 18: Klevis Mino: MongoDB

AggregationMapReduce can be used for batch processing of data and aggregation operations. The aggregation framework enables users to obtain the kind of results for which the SQL GROUP BY clause is used.

Page 19: Klevis Mino: MongoDB

References

mongodb.orgnosql-database.orgdb-engines.comwikipedia.orgCarlo Vaccari’s lecture on Big

Data