41
Storage dei dati con

Storage dei dati con MongoDB

Embed Size (px)

Citation preview

Page 1: Storage dei dati con MongoDB

Storage dei dati con

Page 2: Storage dei dati con MongoDB

#devmean

Page 3: Storage dei dati con MongoDB

The Forrester Wave™: Big Data NoSQL, Q3 2016

Page 4: Storage dei dati con MongoDB

automatic scaling

Document Database high performance high availability

Page 5: Storage dei dati con MongoDB

Collections

Page 6: Storage dei dati con MongoDB

A grouping of MongoDB documents. A collection is the equivalent of an RDBMS table. A collection exists within a single database. Collections do not enforce a schema.

Page 7: Storage dei dati con MongoDB

A record in MongoDB is a document, which is a data structure composed of field and value pairs. MongoDB documents are similar to JSON objects. The values of fields may include other documents, arrays, and arrays of documents.

The advantages of using documents are:• Documents (i.e. objects) correspond to native data types in many programming languages.• Embedded documents and arrays reduce need for expensive joins.• Dynamic schema supports fluent polymorphism.

Page 8: Storage dei dati con MongoDB

{ "_id" : ObjectId("54c955492b7c8eb21818bd09"), "address" : { "street" : "2 Avenue", "zipcode" : "10075", "building" : "1480", "coord" : [ -73.9557413, 40.7720266 ] }, "borough" : "Manhattan", "cuisine" : "Italian", "grades" : [ { "date" : ISODate("2014-10-01T00:00:00Z"), "grade" : "A", "score" : 11 }, { "date" : ISODate("2014-01-16T00:00:00Z"), "grade" : "B", "score" : 17 } ], "name" : "Vella", "restaurant_id" : "41704620"}

BSON is a binary serialization format used to store documents and make remote procedure calls in MongoDB. The BSON specification is located at bsonspec.org.

Double Boolean 64-bit integer

String Date Decimal128

Object Null Min key

Array Regular Expression Max key

Binary data JavaScript

ObjectId 32-bit integer

Page 9: Storage dei dati con MongoDB

ObjectId

ObjectIds are small, likely unique, fast to generate, and ordered.

ObjectId values consists of 12-bytes, where the first four bytes are a timestamp that reflect the ObjectId’s creation, specifically:

• a 4-byte value representing the seconds since the Unix epoch,• a 3-byte machine identifier,• a 2-byte process id, and• a 3-byte counter, starting with a random value.

In MongoDB, each document stored in a collection requires a unique _id field that acts as a primary key. If an inserted document omits the _id field, the MongoDB driver automatically generates an ObjectId for the _id field.

Page 10: Storage dei dati con MongoDB

ObjectId valuesDO NOT

represent a strict insertion order.

Page 11: Storage dei dati con MongoDB

Indexes

Page 12: Storage dei dati con MongoDB

MongoDB creates a unique index on the _id field during the creation of a collection.

Default _id Index

Page 13: Storage dei dati con MongoDB

You cannot drop the index on the _id field.

Page 14: Storage dei dati con MongoDB

db.records.createIndex( { score: 1 } )

Single field Indexes

Page 15: Storage dei dati con MongoDB

sor t o rder does not matter for a sort operation

Page 16: Storage dei dati con MongoDB

db.products.createIndex( { "item": 1, "stock": 1 } )

Compound Indexes

Page 17: Storage dei dati con MongoDB

sort order can matter in determining whether the index can support a sort operation

Page 18: Storage dei dati con MongoDB

MultikeyText2dsphere

2d HashedTTL

Page 19: Storage dei dati con MongoDB

db.people.createIndex( { zipcode: 1 }, { background: true, sparse: true })

Page 20: Storage dei dati con MongoDB

db.people.createIndex({ zipcode: 1 }, { background: true, sparse: true })

Page 21: Storage dei dati con MongoDB

Aggregations

Page 22: Storage dei dati con MongoDB

aggregation framework is modeled on the concept of data processing pipelines.

Page 23: Storage dei dati con MongoDB
Page 24: Storage dei dati con MongoDB

Map / Reduce

Page 25: Storage dei dati con MongoDB

All map-reduce functions are JavaScript and run within the mongod process

Page 26: Storage dei dati con MongoDB
Page 27: Storage dei dati con MongoDB

StorageEngines

Page 28: Storage dei dati con MongoDB

The storage engine is the component of the database that is responsible for managing how data is stored, both in memory and on disk.

Page 29: Storage dei dati con MongoDB

MongoDB supports multiple storage engines, as different engines perform better for specific workloads

Page 30: Storage dei dati con MongoDB

Choosing the appropriate storage engine for your use

case can significantly impact the performance of

your applications

Page 31: Storage dei dati con MongoDB

WiredTiger is the default storage engine starting in MongoDB 3.2. It is well-suited for most workloads and is recommended for new deployments

Page 32: Storage dei dati con MongoDB

WiredTiger provides a document-level concurrency model, checkpointing, and compression, among other features

Page 33: Storage dei dati con MongoDB

MMAPv1 is the original MongoDB storage engine and is the default storage engine for MongoDB versions before 3.2. It performs well on workloads with high volumes of reads and writes, as well as in-place updates.

Page 34: Storage dei dati con MongoDB

The In-Memory Storage Engine is available in MongoDB Enterprise. Rather than storing documents on-disk, it retains them in-memory for more predictable data latencies.

Page 35: Storage dei dati con MongoDB
Page 36: Storage dei dati con MongoDB

https://www.percona.com/blog/2015/12/23/percona-server-for-mongodb-storage-engines-in-iibench-insert-workload/

Page 37: Storage dei dati con MongoDB

Scaling & Availability

Page 38: Storage dei dati con MongoDB
Page 39: Storage dei dati con MongoDB
Page 40: Storage dei dati con MongoDB

ienumerable.it

andreabalducci

mtb.snowboard

Page 41: Storage dei dati con MongoDB