storage dei dati con mongodb
TRANSCRIPT
![Page 1: Storage dei dati con MongoDB](https://reader031.vdocuments.pub/reader031/viewer/2022030310/58f088541a28ab9f088b4629/html5/thumbnails/1.jpg)
Storage dei dati con
![Page 2: Storage dei dati con MongoDB](https://reader031.vdocuments.pub/reader031/viewer/2022030310/58f088541a28ab9f088b4629/html5/thumbnails/2.jpg)
#devmean
![Page 3: Storage dei dati con MongoDB](https://reader031.vdocuments.pub/reader031/viewer/2022030310/58f088541a28ab9f088b4629/html5/thumbnails/3.jpg)
The Forrester Wave™: Big Data NoSQL, Q3 2016
![Page 4: Storage dei dati con MongoDB](https://reader031.vdocuments.pub/reader031/viewer/2022030310/58f088541a28ab9f088b4629/html5/thumbnails/4.jpg)
automatic scaling
Document Database high performance high availability
![Page 5: Storage dei dati con MongoDB](https://reader031.vdocuments.pub/reader031/viewer/2022030310/58f088541a28ab9f088b4629/html5/thumbnails/5.jpg)
Collections
![Page 6: Storage dei dati con MongoDB](https://reader031.vdocuments.pub/reader031/viewer/2022030310/58f088541a28ab9f088b4629/html5/thumbnails/6.jpg)
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](https://reader031.vdocuments.pub/reader031/viewer/2022030310/58f088541a28ab9f088b4629/html5/thumbnails/7.jpg)
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](https://reader031.vdocuments.pub/reader031/viewer/2022030310/58f088541a28ab9f088b4629/html5/thumbnails/8.jpg)
{ "_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](https://reader031.vdocuments.pub/reader031/viewer/2022030310/58f088541a28ab9f088b4629/html5/thumbnails/9.jpg)
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](https://reader031.vdocuments.pub/reader031/viewer/2022030310/58f088541a28ab9f088b4629/html5/thumbnails/10.jpg)
ObjectId valuesDO NOT
represent a strict insertion order.
![Page 11: Storage dei dati con MongoDB](https://reader031.vdocuments.pub/reader031/viewer/2022030310/58f088541a28ab9f088b4629/html5/thumbnails/11.jpg)
Indexes
![Page 12: Storage dei dati con MongoDB](https://reader031.vdocuments.pub/reader031/viewer/2022030310/58f088541a28ab9f088b4629/html5/thumbnails/12.jpg)
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](https://reader031.vdocuments.pub/reader031/viewer/2022030310/58f088541a28ab9f088b4629/html5/thumbnails/13.jpg)
You cannot drop the index on the _id field.
![Page 14: Storage dei dati con MongoDB](https://reader031.vdocuments.pub/reader031/viewer/2022030310/58f088541a28ab9f088b4629/html5/thumbnails/14.jpg)
db.records.createIndex( { score: 1 } )
Single field Indexes
![Page 15: Storage dei dati con MongoDB](https://reader031.vdocuments.pub/reader031/viewer/2022030310/58f088541a28ab9f088b4629/html5/thumbnails/15.jpg)
sor t o rder does not matter for a sort operation
![Page 16: Storage dei dati con MongoDB](https://reader031.vdocuments.pub/reader031/viewer/2022030310/58f088541a28ab9f088b4629/html5/thumbnails/16.jpg)
db.products.createIndex( { "item": 1, "stock": 1 } )
Compound Indexes
![Page 17: Storage dei dati con MongoDB](https://reader031.vdocuments.pub/reader031/viewer/2022030310/58f088541a28ab9f088b4629/html5/thumbnails/17.jpg)
sort order can matter in determining whether the index can support a sort operation
![Page 18: Storage dei dati con MongoDB](https://reader031.vdocuments.pub/reader031/viewer/2022030310/58f088541a28ab9f088b4629/html5/thumbnails/18.jpg)
MultikeyText2dsphere
2d HashedTTL
![Page 19: Storage dei dati con MongoDB](https://reader031.vdocuments.pub/reader031/viewer/2022030310/58f088541a28ab9f088b4629/html5/thumbnails/19.jpg)
db.people.createIndex( { zipcode: 1 }, { background: true, sparse: true })
![Page 20: Storage dei dati con MongoDB](https://reader031.vdocuments.pub/reader031/viewer/2022030310/58f088541a28ab9f088b4629/html5/thumbnails/20.jpg)
db.people.createIndex({ zipcode: 1 }, { background: true, sparse: true })
![Page 21: Storage dei dati con MongoDB](https://reader031.vdocuments.pub/reader031/viewer/2022030310/58f088541a28ab9f088b4629/html5/thumbnails/21.jpg)
Aggregations
![Page 22: Storage dei dati con MongoDB](https://reader031.vdocuments.pub/reader031/viewer/2022030310/58f088541a28ab9f088b4629/html5/thumbnails/22.jpg)
aggregation framework is modeled on the concept of data processing pipelines.
![Page 23: Storage dei dati con MongoDB](https://reader031.vdocuments.pub/reader031/viewer/2022030310/58f088541a28ab9f088b4629/html5/thumbnails/23.jpg)
![Page 24: Storage dei dati con MongoDB](https://reader031.vdocuments.pub/reader031/viewer/2022030310/58f088541a28ab9f088b4629/html5/thumbnails/24.jpg)
Map / Reduce
![Page 25: Storage dei dati con MongoDB](https://reader031.vdocuments.pub/reader031/viewer/2022030310/58f088541a28ab9f088b4629/html5/thumbnails/25.jpg)
All map-reduce functions are JavaScript and run within the mongod process
![Page 26: Storage dei dati con MongoDB](https://reader031.vdocuments.pub/reader031/viewer/2022030310/58f088541a28ab9f088b4629/html5/thumbnails/26.jpg)
![Page 27: Storage dei dati con MongoDB](https://reader031.vdocuments.pub/reader031/viewer/2022030310/58f088541a28ab9f088b4629/html5/thumbnails/27.jpg)
StorageEngines
![Page 28: Storage dei dati con MongoDB](https://reader031.vdocuments.pub/reader031/viewer/2022030310/58f088541a28ab9f088b4629/html5/thumbnails/28.jpg)
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](https://reader031.vdocuments.pub/reader031/viewer/2022030310/58f088541a28ab9f088b4629/html5/thumbnails/29.jpg)
MongoDB supports multiple storage engines, as different engines perform better for specific workloads
![Page 30: Storage dei dati con MongoDB](https://reader031.vdocuments.pub/reader031/viewer/2022030310/58f088541a28ab9f088b4629/html5/thumbnails/30.jpg)
Choosing the appropriate storage engine for your use
case can significantly impact the performance of
your applications
![Page 31: Storage dei dati con MongoDB](https://reader031.vdocuments.pub/reader031/viewer/2022030310/58f088541a28ab9f088b4629/html5/thumbnails/31.jpg)
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](https://reader031.vdocuments.pub/reader031/viewer/2022030310/58f088541a28ab9f088b4629/html5/thumbnails/32.jpg)
WiredTiger provides a document-level concurrency model, checkpointing, and compression, among other features
![Page 33: Storage dei dati con MongoDB](https://reader031.vdocuments.pub/reader031/viewer/2022030310/58f088541a28ab9f088b4629/html5/thumbnails/33.jpg)
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](https://reader031.vdocuments.pub/reader031/viewer/2022030310/58f088541a28ab9f088b4629/html5/thumbnails/34.jpg)
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](https://reader031.vdocuments.pub/reader031/viewer/2022030310/58f088541a28ab9f088b4629/html5/thumbnails/35.jpg)
![Page 36: Storage dei dati con MongoDB](https://reader031.vdocuments.pub/reader031/viewer/2022030310/58f088541a28ab9f088b4629/html5/thumbnails/36.jpg)
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](https://reader031.vdocuments.pub/reader031/viewer/2022030310/58f088541a28ab9f088b4629/html5/thumbnails/37.jpg)
Scaling & Availability
![Page 38: Storage dei dati con MongoDB](https://reader031.vdocuments.pub/reader031/viewer/2022030310/58f088541a28ab9f088b4629/html5/thumbnails/38.jpg)
![Page 39: Storage dei dati con MongoDB](https://reader031.vdocuments.pub/reader031/viewer/2022030310/58f088541a28ab9f088b4629/html5/thumbnails/39.jpg)
![Page 40: Storage dei dati con MongoDB](https://reader031.vdocuments.pub/reader031/viewer/2022030310/58f088541a28ab9f088b4629/html5/thumbnails/40.jpg)
ienumerable.it
andreabalducci
mtb.snowboard
![Page 41: Storage dei dati con MongoDB](https://reader031.vdocuments.pub/reader031/viewer/2022030310/58f088541a28ab9f088b4629/html5/thumbnails/41.jpg)