slide1 n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
MongoDB PowerPoint Presentation
Download Presentation
MongoDB

Loading in 2 Seconds...

play fullscreen
1 / 29

MongoDB - PowerPoint PPT Presentation


  • 267 Views
  • Uploaded on

MongoDB. Lugar y Fecha. Telefónica I+D. Mongodb is. A document-oriented storage . JSON- style documents with dynamic schemas offer simplicity and power . Querying . Rich , document -base queries . Fast In-Place Updates . Atomic modifiers for contention -free performance.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'MongoDB' - danika


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
slide1

MongoDB

Lugar y Fecha

Telefónica I+D

slide2

Mongodb is...

  • A document-orientedstorage.

JSON-styledocumentswithdynamicschemasoffersimplicity and power.

  • Querying.

Rich, document-base queries.

  • Fast In-Place Updates.

Atomicmodifiersforcontention-free performance.

  • Full indexSupport.

Indexonanyattribute.

  • Auto-Sharding.

Scalehorizontallywithoutcompromisingfuncionality.

  • Replication & High Availability.

Mirroracross LAN forscale.

  • Map/Reduce

Flexible (butlimited) data processing.

2

slide3

Mongodb is Not...

  • A ACID database.
  • A batch procesing platform.

3

slide4

MongodbArchitecture

  • MongoDB is a document-oriented database, but this not implica that it has the same concepts of RDMS, one of this concepts is the “database”, within a MongoDB instance you can have zero or more databases, each acting as high-level containers for everything else
  • A database can have zero or more “collections”, A collection shares enough in common with a traditional table, a collection is the same as a table with a indeterminate number of columns.
  • Collections is made up of zero or more documents. Again, a document can safely be thought of as a “row”.
  • A document is made up one or more fields, which yo can probable guess are a lot like “columns”.
  • Indexes in MongoDB function much like their RDBMS counterparts.
  • Cursors are different than the other five concepts but they are important enough. The import thing to understand about cursors is that when you ask MongoDB for data, it returns a cursor, which we can do things to, such as counting or skipping ahead, without actually pulling down data.

4

slide5

MongodbArchitecture

  • Mongo uses memory mapped files to access data, which results in large numbers being displayed in tools like top for the mongod process.
  • Mongo eliminates the need (in some cases) for a separate object caching layer. Queries that result in file system RAM cache hits are very fast as the object's representation in the database is very close to its representation in application memory. Also, the MongoDB can scale to any level and provides an object cache and database integrated together, which is very helpful as there is no risk of retrieving stale data from the cache. In addition, the complex queries a full DBMS provides are also possible.
  • MongoDB supports write-ahead journaling of operations to facilitate fast crash recovery and durability in the storage

5

slide7

Mongodb Api

  • The conection to the databases front the aplications are a propiatery protocol that runs over TCP/IP in binary format. The apis have a control the write behavior for with various options, as well as exception raising on error conditions.
      • NONE: No exceptions are raised, even for network issues
      • NORMAL: Exceptions are raised for network issues, but not server errors
      • SAFE: Exceptions are raised for network issues, and server errors; waits on a server for the write operation
      • FSYNC_SAFE: Exceptions are raised for network issues, and server errors and the write operation waits for the server to flush the data to disk
      • REPLICAS_SAFE: Exceptions are raised for network issues, and server errors; waits for at least 2 servers for the write operation

7

slide8

Mongodb Api

  • Insert: it is the basic method for adding data into MongoDB. When we insert a new document into a collection this will add an “_id” key to the document before save it. When insert a new object into the collection, the driver coverts the data structure into BSON, which it then sends to the database. Then it saves the document, and regenerate the _id index, and all the secondary index that the new object has.
    • db.collection.insert(doc);
    • db.collection.save(doc); // updates if exists; inserts if new (_id)
  • Delete: it is the basic method for deleting data.
    • db.videos.remove( { rating : { $lt : 3.0 }, $atomic : true } )

8

slide9

Mongodb Api

  • Query: MongoDB's support for dynamic (ad hoc) queries. MongoDB supports a number of query objects for fetching data.
    • Db.collection.find(query,fields)
  • Method:
    • count()
    • sort()
    • limit()
    • skip()

9

slide11

Mongodb Api

  • Update: replaces the document matching criteria entirely with objNew. If you only want to modify some fields, you should use the atomic modifiers below.
    • db.collection.update( criteria, objNew, upsert, multi ).
  • Arguments
    • criteria - query which selects the record to update;
    • objNew - updated object or $ operators (e.g., $inc) which manipulate the object
    • upsert - if this should be an "upsert"; that is, if the record does not exist, insert it
    • multi - if all documents matching criteria should be updated

11

slide13

Mongodb Api

  • Upserts : it is a special type of update, in where if no document is found to upate, a new document will be created in a atomic operation.
  • db.jobs.findAndModify({query: {},update : {}, fields: {}, new: false } )

13

slide14

MongodbApi

  • Example in console.

14

slide15

MongodbIndex

  • These indexes are implemented as "B-Tree" indexes.
  • the indexes in MongoDB work a lot like indexes in a relational database: they help improve query and sorting performance, the indexes are created manual, and could be unique, ascending or descending.
  • Index on _id is always created and can`t be deleted.
  • I can index on a key inside of an embedded document.

15

slide16

MongodbIndex

  • Example in console.

16

slide17

MongodbSharding

  • MongoDBsupports auto-sharding, and auto.balancing.
  • Sharding is an approach to scalability which separates your data across multiple servers.
  • With sharding we instead scale horizontally to achieve the same computacional/storage/memory footprint from smaller servers.
  • We will show the vertically scale db and the horizontally scaled dbfor comparison.
  • A sharded collection has a shard key. The collection is partitioned using this key. In this example we uses ident.
    • {ident:…, data:…}

17

slide18

MongodbSharding

  • There are three components in sharding.
    • Mongos: routing procesing.
    • Config servers: store the metadata.
    • Mongod: store the data.

18

slide19

MongodbSharding

  • Metadata is maintained on chunks which are represented by shard key ranges.

19

slide20

MongodbSharding

  • Querys with the shard key are sent to the node who has this shard.

20

slide21

MongodbSharding

  • Querys with the shard key and the data are in some shard, it as sent to these nodes.

21

slide22

MongodbSharding

  • Querys with the no shard key are sent to all nodes.

22

slide23

MongodbSharding

  • Example in console.

23

slide24

MongodbReplication

  • MongoDBreplication works similarly to how relational database replication works. Writes are sent to a single server, the master, which then synchronizes itself to one or more other servers, the slaves. If the master goes down, a slave can be promoted to act as the new master.
  • While replication can improve performance (by distributing reads), its main purpose is to increase reliability.
  • There are two types of replication:
    • Master slaver replication.
    • Replica sets.

24

slide25

MongodbReplication

  • Master slaver replication.
  • Setup master:
    • bin/mongod–master –oplogSize 100
  • Setup slaver:
    • bin/mongod --slave --source <IP>[:<port>] --slavedelay1 --autoresync

25

slide26

MongodbReplication

  • Replica sets.
    • mongod--replSet“setname”
  • Shell in one node
  • cfg = {
  • ... _id : “setname",
  • ... members : [
  • ... { _id : 0, host : “host1" },
  • ... { _id : 1, host : “host2" },
  • ... { _id : 2, host : “host3" } ] }
  • rs.initiate(cfg)
  • rs.status()
  • Options

26

slide27

MongodbMap&Reduce

  • DB is useful for batch processing of data and aggregation operations.

27

slide28

MongodbTools

  • Mongodump: export to binary data
  • Mongoexport: export to csv
  • Mongofiles: load data into mongodb
  • MongoImport: import txt, csv or json data
  • mongoRestore: mongorestore takes the output from mongodump: and restores it.
  • mongoSniff: This utility is to MongoDB what tcpdump is to TCP/IP
  • Mongostat: Use the mongostat utility to quickly view statistics on a running mongod instance

28