• No results found

m101n Mongodb for Net Developers

N/A
N/A
Protected

Academic year: 2021

Share "m101n Mongodb for Net Developers"

Copied!
12
0
0

Loading.... (view fulltext now)

Full text

(1)

LECTURE WEEK 1: INTRODUCTION

Welcome to the class Introduction to M101N What is MongoDB?

MongoDB Relative to Relational Application Architecture

Quick Introduction to the Mongo Shell Introduction to JSON

Installing MongoDB (windows) MongoDB is Schemaless JSON Revisited

JSON Spec

Introduction to Our Class Project, the Blog Blog in Relational Tables

Blog in Documents

Introduction to Schema Design H1.1

WEEK 2: CRUD Introduction to Week 2 CRUD and the Mongo Shell Secrets of the Mongo Shell BSON Introduced

Inserting Docs

Introduction to findOne Introduction to find

Querying Using field Selection Querying Using $gt and $lt Inequalities on Strings Using regexes, $exists, $type Using $or

Using $and

Querying Inside Arrays Using $in and $all Queries with Dot Notation Querying, Cursors Counting Results

Wholesale Updating of a Document Using the $set Command

Using the $unset Command

Using $push, $pop, $pull, $pushAll, $pullAll, $addToSet Upserts

Multi-update Removing Data

getLastError (MongoDB v2.4 and earlier) Getting Started with the .NET Driver

.NET driver, MongoClient, MongoDatabase, MongoCollection .NET driver, document representation

.NET Driver, Poco Representation .NET Driver, InsertOne

.NET Driver, Find

https://youtu.be/B_MBXbP9LSE https://youtu.be/hVcGEb7HiDc https://youtu.be/Lfl8hdQOi6Y https://youtu.be/-KIC1LXxcGM https://youtu.be/RDEhRO_FwGE https://youtu.be/e18vCIdQKp4 https://youtu.be/PTATjNSjbJ0 https://youtu.be/sBdaRlgb4N8 https://youtu.be/uKB-Hoqs6zI https://youtu.be/CTffxoSSLqg https://youtu.be/kOrsT94-A28 https://youtu.be/NTDgDqgs9gk https://youtu.be/kqglm5c52oI https://youtu.be/JFkBoIxjLqo https://youtu.be/6XE3wZCPiZ8 https://youtu.be/TV7RWf6DBbc https://youtu.be/H_OcFFkRYX0 https://youtu.be/C7LinMC2o5o https://youtu.be/IIIzjPp-IRE https://youtu.be/K3J6WvDW-Hc https://youtu.be/qqfVxGLIrLg https://youtu.be/w9V0fJsDwbQ https://youtu.be/8kKfFK6a0Ak https://youtu.be/UIg86QjSoyY https://youtu.be/FHLrz4VGzkg https://youtu.be/imCCKOevU3c https://youtu.be/lI-jhqYf1JY https://youtu.be/BW5ElNCRZps https://youtu.be/hYk7pjgjjzc https://youtu.be/jvEqwW75Bus https://youtu.be/QU2NrkviORE https://youtu.be/NrjFECIfwqk

https://youtu.be/3jA6iFSEJOI When can you change the behavior of a cursor, by applying a sort, skip, or limit to it? https://youtu.be/eKD5bVmNQMI https://youtu.be/g7Fi1xXsuvU https://youtu.be/XyhNjs2pNVc https://youtu.be/LpErz8jLW0I https://youtu.be/GOn0EWKDQoY https://youtu.be/Dy2p8k3EZs4 https://youtu.be/2GNNdUmDL-4 https://youtu.be/5K0t1dU8IJY https://youtu.be/a6o0TQjUMug https://youtu.be/ujuCwFiqfpA https://youtu.be/3xaIrMiGzT0 https://youtu.be/-cOlCv2ptCA https://youtu.be/wYHn8sqBMuI https://youtu.be/k3J1tLnJSqc

(2)

.NET Driver, Find with Filters

.NET Driver, Find with Skip, Limit and Sort .NET Driver, Find with Projections

.NET Driver, UpdateOne and UpdateMany .NET Driver, DeleteOne and DeleteMany

.NET Driver, FindOneAndUpdate, FindOneAndReplace, Fin .NET driver, BulkWrite

Homework 2.1

WEEK 3: SCHEMA DESIGN Homework 2.2

Homework 2.3 Introduction to Week 3

MongoDB Schema Design Relational Normalization Mongo Design for Blog Alternative Schema for Blog Living Without Constraints Living Without Transactions One to One Relations One to Many Relations Many to Many Relations Multikeys

Benefits of Embedding Trees

When to Denormalize

Homework 3.1

WEEK 4: PERFORMANCE Homework 3.2

Homework 3.3 Introduction to Week 4

Storage Engines: Introduction Storage Engines: MMAPv1 Storage Engines: WiredTiger Indexes

Creating Indexes

Discovering (and Deleting) Indexes Multikey Indexes

Dot Notation and Multikey Index Creation Option, Unique Index Creation, Sparse Index Creation, Background Using Explain

Explain: Verbosity Covered Queries When is an Index Used? How Large is Your Index? Number of Index Entries Geospatial Indexes Geospatial Spherical Text Indexes

Efficiency of Index Use

Efficiency of Index Use Example Logging Slow Queries

Profiling Mongotop https://youtu.be/yEiIBTMrN7E https://youtu.be/vvm1RX85yqo https://youtu.be/pZTlQgPSi_M https://youtu.be/XpHsKDcWlrM https://youtu.be/dDo891eZfe0 https://youtu.be/o0d6vYZLhqI https://youtu.be/Q2na8Ks_sLM https://youtu.be/9urnY4OcuNM https://youtu.be/AABYJM12qF4 https://youtu.be/GX__f2s4hd8 https://youtu.be/PRylEHH5t84 https://youtu.be/ZvqNWVWB2-o https://youtu.be/YFRMkDPaams https://youtu.be/FfRr3qjRfww https://youtu.be/cCsfon0vUlQ https://youtu.be/EIaP1KbVkUc https://youtu.be/fEYYjZ7zEHc https://youtu.be/KtIY4Q1tUao https://youtu.be/XIN0Dqht08Q https://youtu.be/lIjXyQklGWY https://youtu.be/jDZ-HFoJ0vg https://youtu.be/GGMfM3pYK_4 https://youtu.be/YvK7I9fYpK4 https://youtu.be/os3591KviNM https://youtu.be/aNsugW7r3mM https://youtu.be/U3iWPF5jP-g https://youtu.be/xi2gtzZez6Q https://youtu.be/dX49IcmTrGA https://youtu.be/_NGwn_X82Dw https://youtu.be/wT0_ktAZbBg https://youtu.be/D-Ra5TEaaL4 https://youtu.be/ZznHByqtTMA https://youtu.be/AchmKNj2qhw https://youtu.be/r5YeICVzDjQ https://youtu.be/WxXVun6bZ20 https://youtu.be/QyV79jsSJ9Y https://youtu.be/JyQlxDc549c https://youtu.be/wjA0eo_lihg https://youtu.be/xiujksUfzUA https://youtu.be/UKUDYqNVL6I https://youtu.be/pULU4DVsUWQ https://youtu.be/nLau5Fx9LC8 https://youtu.be/JJmIf0pn100 https://youtu.be/g032EW67SRA https://youtu.be/aWuvC-O7Qkk https://youtu.be/pN1Yhrup9-I https://youtu.be/D9YLXgy7NYo

(3)

Mongostat

Sharding Overview Homework 4.1 Homework 4.2 Homework 4.3

Homework 4.4 db.profile.find({ns: "school2.students" } WEEK 5: AGGREGATION FRAMEWORK

Introduction to Week 5 Simple Aggregation Example The Aggregation Pipeline Simple Example Expanded Compound Grouping Using a document for _id Aggregation Expressions Using $sum

Using $avg Using $addToSet Using $push

Using $max and $min Double $group stages Using $project Using $match Using $sort

Using $limit and $skip Revisiting $first and $last Using $unwind

$unwind example Double $unwind

Mapping between SQL and Aggregation Some Common SQL examples

Limitations of the Aggregation Framework Aggregation in .NET

WEEK 6: APPLICATION ENGINEERING Introduction to Week 6

Write Concern Network Errors

Introduction to Replication Replica Set Elections Write Consistency Creating a Replica Set Replica Set Internals Failover and Rollback

Connecting to a Replica Set from .NET Driver Bad Things Happen to Good Nodes

Write Concern Revisited Read Preferences

Review of Implications of Replication Introduction to Sharding

Building a Sharded Environment

https://youtu.be/E2aDTSes3Wc https://youtu.be/BDxT-VZdYqc

db.products.find( { 'brand' : "GE" } ).sort( { price : 1 } ) The query examines 251120 documents.

The problem you'll notice is the

https://youtu.be/EaEIHm3CMQM https://youtu.be/DQBXCsjeO5c https://youtu.be/AuO8CEkTG6Y https://youtu.be/3lEpnMcfpCs https://youtu.be/qTbtax_cKcc https://youtu.be/zoN4cj_XQzY https://youtu.be/L4G14MTfTgQ https://youtu.be/93MSz3uDC1A https://youtu.be/baIDZ-M5j7w https://youtu.be/YzURaZnKI9s https://youtu.be/LQcBM-g0ACY https://youtu.be/BYoNX4trjOQ https://youtu.be/EIWF9Oxeb8M https://youtu.be/TbQ2PI5Fib0 https://youtu.be/7RtHG90Hrbw https://youtu.be/HUEtV7omSb8 https://youtu.be/o5hzYKXUyrU https://youtu.be/JOdAnxVAMwc https://youtu.be/E4aYOQPeQvI https://youtu.be/U_4Enh2TTp4 https://youtu.be/YXGL27217B8 https://youtu.be/auL2R0XKlyM https://youtu.be/ep2gLSR6C0U https://youtu.be/U_gRSxEq3c0 https://youtu.be/Lyysv6LpHDw https://youtu.be/BmQuvmpt_ZQ https://youtu.be/oRDYNWCYnGo https://youtu.be/xWNzCkTCN-M https://youtu.be/f1WTYGORU3w https://youtu.be/WFXSVHO78bQ https://youtu.be/Oqf_Eza-s1M https://youtu.be/flCFVFBRsKI https://youtu.be/6GbrJmxCEl0 https://youtu.be/IW1oW_Adlt0 https://youtu.be/pli6Gsi7Z-k https://youtu.be/7ZYqrmGOlpc https://youtu.be/5VyXyccjS3k https://youtu.be/mhHaS4ZWzZE https://youtu.be/K5ISnvYKQFQ https://youtu.be/_GfDqa1qRl0 https://youtu.be/dn45G2yw20A

(4)

Implications of Sharding Sharding + Replication Choosing a Shard Key WEEK 7: CASE STUDIES Introduction to Week 7

Interview with Charity Majors, Parse Interview with Ryan Bubinski, Codecademy FINAL EXAM https://youtu.be/ig278F60gRA https://youtu.be/gkUCUbM0oEg https://youtu.be/8q2GB3QSBSI https://youtu.be/eL054c6nkaY https://youtu.be/PTp0A8_IVAY https://youtu.be/RkPmVQNesZA

(5)

ANSWER

Homework & Final Exam

{"fruit":["apple", "pear", "peach"]}

5 1

42 { "title" : "Star Wars", {} -1030

db.scores.find({type: "essay", score: 50},{_id:false, student:true})

2

db.users.find({name : {$regex : "q"}, email:{$exists:true}}) db.scores.find({$or:[{score:{$lt:50}},{score:{$gt:90}}]})

db.scores.count({type:"essay", score:{$gt:90}})

MongoDB.Driver

doc.Add(“field”, “value”); doc[“field”] = “value”;

ToArrayAsync https://youtu.be/CAR42sMkXEo https://youtu.be/IAvnMgvHuLw https://youtu.be/YQTqdLe3W4M https://youtu.be/uWcOsdV4Iz4 https://youtu.be/wiwOEG_6ojs https://youtu.be/pLW6hX-hvAA https://youtu.be/nWOt4VN6Y3g https://youtu.be/a6TFwpCoLoY https://youtu.be/4hsTQrMs-xY https://youtu.be/BRAVnBz3ogE https://youtu.be/uN_wf5a3BE4 https://youtu.be/ouHFZgtEAuU https://youtu.be/ouHFZgtEAuU https://youtu.be/tY7I1l8JdDI https://youtu.be/ZRWT0lcHsoU https://youtu.be/yMi7PwOoqXY https://youtu.be/diimYkvr374 https://youtu.be/oIkSajy8NLw https://youtu.be/gwECaa4N9Xc https://youtu.be/6O1UGHwuEww https://youtu.be/yiEjK_V008s

This can be done at any point before the first document is called and before you've checked to see if it is empty.

https://youtu.be/Uozp0diXOc8 https://youtu.be/pwnRUdtI8lY

https://youtu.be/G2e5ZxqR6nw db.users.update({'username': 'splunker'}, {'$set': {'country': 'RU'}}) https://youtu.be/-CzLvQS12wY

https://youtu.be/bGbiIGEM0FY https://youtu.be/Loo5XKQAryM https://youtu.be/puGW4t5wmOU https://youtu.be/AGvJs8xqZJg

(6)

22 54 x db.places.find({location:{$near:[74,140]}}).limit(3) - https://youtu.be/A4x4kE02pSc - https://youtu.be/Wfsll8tt_ng https://youtu.be/OVDnLJXpqNE https://youtu.be/s5E0T4caqj4 https://youtu.be/3VckBMGInic https://youtu.be/189zABW3HHk https://youtu.be/BjW64RkzlGg https://youtu.be/KQcspnr-Y2M https://youtu.be/80P6yVSkKQY https://youtu.be/SR76BjJl-PQ

This is the basic idea behind why we call it MMAPv1. https://youtu.be/dmnPb-hhVHM https://youtu.be/5Z6V8mJ8eS4 https://youtu.be/9FUOetT45AM https://youtu.be/caSP0dO02iU https://youtu.be/ia6dzcj-ZMk https://youtu.be/yV_KEDEzOyc https://docs.mongodb.org/manual/core/index-creation/?_ga=1.173842341.745792798.1450433650#index-creation-background https://youtu.be/Gpj_s49H_rQ https://youtu.be/qBFFnnoK1NA https://youtu.be/MxHsmUXjkKo

db.foo.find( { a : 3 } ) & db.foo.find( { c : 1 } ).sort( { a : 1, b : 1 } )

https://youtu.be/mXHUIghDkFw https://youtu.be/4UW_oMSswTo https://youtu.be/hVLa0H7Oe98

https://youtu.be/YtRnCyKS1VE db.stores.find({ loc:{ $near: { $geometry: { type: "Point", coordinates: [-130, 39]}, $maxDistance:1000000 } } })

https://youtu.be/7OK0e1gftjg https://docs.mongodb.org/manual/reference/operator/query/regex/?_ga=1.188480174.745792798.1450433650#index-use

complete the result set, without the need to scan a substantially larger number of index keys (or documents) in order to Equality fields before range fields Sort fields before range fields Equality fields before sort fields

db.system.profile.find({millis: {$gt:1000}}).sort({ts:-1})

(7)

https://youtu.be/etOEgMTFKW0

15820

db.products.aggregate([{$group: {"_id": "$category", "num_products":{"$sum":1}}}]) nu Transpose 3 5 $first, $last db.zips.aggregate([{"$group":{"_id":"$state", "population":{$sum:"$pop"}}}]) db.zips.aggregate([{"$group":{"_id":"$state", "average":{$avg:"$pop"}}}]) db.zips.aggregate([{"$group":{"_id":"$city", "postal_codes":{"$addToSet":"$_id"}}}]) Same result db.zips.aggregate([{$group:{"_id":"$state", pop:{$max:"$pop"}}}]) 52 and 22

db.zips.aggregate([{$project:{_id:0, city:{$toLower:"$city"}, pop:1, state:1, zip:"$_id"}}]) db.zips.aggregate([{$match:{pop:{$gt:100000}}}]) db.zips.aggregate([{$sort:{state:1, city:1}}]) 0 54 6 $push

The getmore column concerns the number of requests per time interval to get additional data from a cursor

db.products.find( { $and : [ { price : { $gt : 30 } },{ price : { $lt :

50 } } ] } ).sort( { brand : 1 } )

The query uses an index to determine the order in which to return result documents. 'db.posts.explain("executionStats").find({ "Tags" : "asd"}).sort({"CreatedAtUtc":-https://youtu.be/Nt0cQI86G40 https://youtu.be/mcnGfI69rRc https://youtu.be/nr1E1qTyIHU https://youtu.be/bIlwnlYBRA0 https://youtu.be/kJ0k2na4ukU https://youtu.be/ATO_s_Ah08o https://youtu.be/tT6Jx8s9dTc https://youtu.be/zGcTxUQuLGE https://youtu.be/hFqDvVXtm6E https://youtu.be/sHCdOiCispA https://youtu.be/J-asAAEHJ0Q https://youtu.be/IGN0lXg-kJ0 https://youtu.be/CHGiumXE-pU https://youtu.be/-cghyd6AHHA https://youtu.be/joRw-fqCIWA https://youtu.be/MVSoinykIJA https://youtu.be/Xfl3m7wz8ts https://youtu.be/jAWL-BJD0tI

https://youtu.be/pziFq1oVRI4 $push operator?

https://youtu.be/6b5-Eg-vNMY https://youtu.be/xrruRJHSpzc https://youtu.be/XCssKzhlnZU https://youtu.be/vrUxTTD-XwA https://youtu.be/SjaJEYK1u3E https://youtu.be/ibZVf59aUj8 https://youtu.be/kGDhzwLZmXU https://youtu.be/t3rNxRg6WZE https://youtu.be/hQrCwRplszo https://youtu.be/wWG5GUt76lw https://youtu.be/8wuWShep8Qs https://youtu.be/hy1MDmvRElQ

(8)

https://youtu.be/vfl0hqdgB3Q https://youtu.be/hnuiYokdO7g https://youtu.be/91tO_iGga5w

(9)

{ "a" : 1, "b" : { "b" : 1

db.scores.find({type: "essay", score: 50},{_id:false, student:true})

db.users.find({name : {$regex : "q"}, email:{$exists:true}}) db.scores.find({$or:[{score:{$lt:50}},{score:{$gt:90}}]})

(10)

db.places.find({location:{$near:[74,140]}}).limit(3) All 3

(11)

db.products.aggregate([{$group: {"_id": "$category", "num_products":{"$sum":1}}}])

db.zips.aggregate([{"$group":{"_id":"$state", "population":{$sum:"$pop"}}}]) db.zips.aggregate([{"$group":{"_id":"$state", "average":{$avg:"$pop"}}}]) db.zips.aggregate([{"$group":{"_id":"$city", "postal_codes":{"$addToSet":"$_id"}}}]) db.zips.aggregate([{$group:{"_id":"$state", pop:{$max:"$pop"}}}])

db.zips.aggregate([{$project:{_id:0, city:{$toLower:"$city"}, pop:1, state:1, zip:"$_id"}}]) db.zips.aggregate([{$match:{pop:{$gt:100000}}}])

Yes

the faults column appears only in the mmapv1 output

(12)

References

Related documents

During our observed period we see an increasing in the market share of renewables and we will test whether for the German market the influence of solar and wind

Different digital cameras have dif- ferent memory card slots, so make sure you know what kind of card your camera takes.. If you don’t know, visit the Memory Cards & Sticks page

Through Monte Carlo simulations, probabilistic fatigue load spectra for critical hot-spots on different components of the connection, such as holes, rivets, angle fillets were

The specific objective is to examine the role of information communication technology (ICT) in Knowledge Management and academic staff retention in selected

We have recently developed a model of the canine ventricular myocyte which incorporates local control of CICR via a description of the stochastic gating of individual LCCs and RyRs

While S-MPs dominated total plastic debris in tidal creek water and bare flat sites, the contribution of L-MPs was higher in edge and marsh sites.. Fragments were the largest

Each symbol in a behavioral sequence is a (possibly empty) set of these operations subject 1.0 two restrictions: there is at most one time delay operation in any set (if there is