mongodb - assets.astrails.comassets.astrails.com/presentations/database2011/mongodb-for-sql-a… ·...
TRANSCRIPT
![Page 1: MongoDB - assets.astrails.comassets.astrails.com/presentations/database2011/MongoDB-for-SQL-a… · mongo MongoDB shell version: 1.6.5 connecting to: test > help()!db.help() help](https://reader034.vdocuments.site/reader034/viewer/2022050715/5f0c7e3e7e708231d435ad77/html5/thumbnails/1.jpg)
MongoDBNoSQL for SQL addicts
Vitaly Kushnerastrails.com
![Page 2: MongoDB - assets.astrails.comassets.astrails.com/presentations/database2011/MongoDB-for-SQL-a… · mongo MongoDB shell version: 1.6.5 connecting to: test > help()!db.help() help](https://reader034.vdocuments.site/reader034/viewer/2022050715/5f0c7e3e7e708231d435ad77/html5/thumbnails/2.jpg)
NoSQL
![Page 3: MongoDB - assets.astrails.comassets.astrails.com/presentations/database2011/MongoDB-for-SQL-a… · mongo MongoDB shell version: 1.6.5 connecting to: test > help()!db.help() help](https://reader034.vdocuments.site/reader034/viewer/2022050715/5f0c7e3e7e708231d435ad77/html5/thumbnails/3.jpg)
• column databases
• key value stores
• document databases
![Page 4: MongoDB - assets.astrails.comassets.astrails.com/presentations/database2011/MongoDB-for-SQL-a… · mongo MongoDB shell version: 1.6.5 connecting to: test > help()!db.help() help](https://reader034.vdocuments.site/reader034/viewer/2022050715/5f0c7e3e7e708231d435ad77/html5/thumbnails/4.jpg)
Documents
![Page 5: MongoDB - assets.astrails.comassets.astrails.com/presentations/database2011/MongoDB-for-SQL-a… · mongo MongoDB shell version: 1.6.5 connecting to: test > help()!db.help() help](https://reader034.vdocuments.site/reader034/viewer/2022050715/5f0c7e3e7e708231d435ad77/html5/thumbnails/5.jpg)
Data Types• string
• integer
• float
• boolean
• symbol
• object id
• date
• regular expression
• code
• null
• array
• document
![Page 6: MongoDB - assets.astrails.comassets.astrails.com/presentations/database2011/MongoDB-for-SQL-a… · mongo MongoDB shell version: 1.6.5 connecting to: test > help()!db.help() help](https://reader034.vdocuments.site/reader034/viewer/2022050715/5f0c7e3e7e708231d435ad77/html5/thumbnails/6.jpg)
{ name: "Vitaly Kushner", company: "Astrails", presentation: { title: "MongoDB", subtitle: "NoSQL for SQL addicts" }}
![Page 7: MongoDB - assets.astrails.comassets.astrails.com/presentations/database2011/MongoDB-for-SQL-a… · mongo MongoDB shell version: 1.6.5 connecting to: test > help()!db.help() help](https://reader034.vdocuments.site/reader034/viewer/2022050715/5f0c7e3e7e708231d435ad77/html5/thumbnails/7.jpg)
Databases & Collections
![Page 8: MongoDB - assets.astrails.comassets.astrails.com/presentations/database2011/MongoDB-for-SQL-a… · mongo MongoDB shell version: 1.6.5 connecting to: test > help()!db.help() help](https://reader034.vdocuments.site/reader034/viewer/2022050715/5f0c7e3e7e708231d435ad77/html5/thumbnails/8.jpg)
Shell
![Page 9: MongoDB - assets.astrails.comassets.astrails.com/presentations/database2011/MongoDB-for-SQL-a… · mongo MongoDB shell version: 1.6.5 connecting to: test > help()!db.help() help](https://reader034.vdocuments.site/reader034/viewer/2022050715/5f0c7e3e7e708231d435ad77/html5/thumbnails/9.jpg)
➜ mongoMongoDB shell version: 1.6.5connecting to: test> help() db.help() help on db methods db.mycoll.help() help on collection methods rs.help() help on replica set methods help connect connecting to a db help help admin administrative help help misc misc things to know ...
![Page 10: MongoDB - assets.astrails.comassets.astrails.com/presentations/database2011/MongoDB-for-SQL-a… · mongo MongoDB shell version: 1.6.5 connecting to: test > help()!db.help() help](https://reader034.vdocuments.site/reader034/viewer/2022050715/5f0c7e3e7e708231d435ad77/html5/thumbnails/10.jpg)
INSERT INTO table (column) VALUES (“value”)
![Page 11: MongoDB - assets.astrails.comassets.astrails.com/presentations/database2011/MongoDB-for-SQL-a… · mongo MongoDB shell version: 1.6.5 connecting to: test > help()!db.help() help](https://reader034.vdocuments.site/reader034/viewer/2022050715/5f0c7e3e7e708231d435ad77/html5/thumbnails/11.jpg)
db.a.insert({column: “value”})
![Page 12: MongoDB - assets.astrails.comassets.astrails.com/presentations/database2011/MongoDB-for-SQL-a… · mongo MongoDB shell version: 1.6.5 connecting to: test > help()!db.help() help](https://reader034.vdocuments.site/reader034/viewer/2022050715/5f0c7e3e7e708231d435ad77/html5/thumbnails/12.jpg)
> show dbsadminlocaltest> use introswitched to db intro> db.a.insert({a: "test"})> show dbsadminintrolocaltest> show collectionsasystem.indexes> db.a.find(){ "_id" : ObjectId("4d2eaab9d126330e1e0f9899"), "a" : "test" }
![Page 13: MongoDB - assets.astrails.comassets.astrails.com/presentations/database2011/MongoDB-for-SQL-a… · mongo MongoDB shell version: 1.6.5 connecting to: test > help()!db.help() help](https://reader034.vdocuments.site/reader034/viewer/2022050715/5f0c7e3e7e708231d435ad77/html5/thumbnails/13.jpg)
{ "_id" : ObjectId("4d2eaab9d126330e1e0f9899"), "a" : "test" }
![Page 14: MongoDB - assets.astrails.comassets.astrails.com/presentations/database2011/MongoDB-for-SQL-a… · mongo MongoDB shell version: 1.6.5 connecting to: test > help()!db.help() help](https://reader034.vdocuments.site/reader034/viewer/2022050715/5f0c7e3e7e708231d435ad77/html5/thumbnails/14.jpg)
> db.a.insert({_id: 1, just: "test"})> db.a.find(){ "_id" : ObjectId("4d2eaab9d126330e1e0f9899"), "a" : "test" }{ "_id" : 1, "just" : "test" }
![Page 15: MongoDB - assets.astrails.comassets.astrails.com/presentations/database2011/MongoDB-for-SQL-a… · mongo MongoDB shell version: 1.6.5 connecting to: test > help()!db.help() help](https://reader034.vdocuments.site/reader034/viewer/2022050715/5f0c7e3e7e708231d435ad77/html5/thumbnails/15.jpg)
• Timestamp (4 bytes)
• machine (3 bytes)
• pid (2 bytes)
• increment (3 bytes)
Object ID
![Page 16: MongoDB - assets.astrails.comassets.astrails.com/presentations/database2011/MongoDB-for-SQL-a… · mongo MongoDB shell version: 1.6.5 connecting to: test > help()!db.help() help](https://reader034.vdocuments.site/reader034/viewer/2022050715/5f0c7e3e7e708231d435ad77/html5/thumbnails/16.jpg)
DELETE FROM table WHERE column = value;
![Page 17: MongoDB - assets.astrails.comassets.astrails.com/presentations/database2011/MongoDB-for-SQL-a… · mongo MongoDB shell version: 1.6.5 connecting to: test > help()!db.help() help](https://reader034.vdocuments.site/reader034/viewer/2022050715/5f0c7e3e7e708231d435ad77/html5/thumbnails/17.jpg)
> db.a.remove({_id: 1})
![Page 18: MongoDB - assets.astrails.comassets.astrails.com/presentations/database2011/MongoDB-for-SQL-a… · mongo MongoDB shell version: 1.6.5 connecting to: test > help()!db.help() help](https://reader034.vdocuments.site/reader034/viewer/2022050715/5f0c7e3e7e708231d435ad77/html5/thumbnails/18.jpg)
UPDATE table SET column1 = value1 WHERE column2 = value2;
![Page 19: MongoDB - assets.astrails.comassets.astrails.com/presentations/database2011/MongoDB-for-SQL-a… · mongo MongoDB shell version: 1.6.5 connecting to: test > help()!db.help() help](https://reader034.vdocuments.site/reader034/viewer/2022050715/5f0c7e3e7e708231d435ad77/html5/thumbnails/19.jpg)
db.a.update({a: "test"}, {foo: "bar"})
![Page 20: MongoDB - assets.astrails.comassets.astrails.com/presentations/database2011/MongoDB-for-SQL-a… · mongo MongoDB shell version: 1.6.5 connecting to: test > help()!db.help() help](https://reader034.vdocuments.site/reader034/viewer/2022050715/5f0c7e3e7e708231d435ad77/html5/thumbnails/20.jpg)
> db.a.find(){ "_id" : ObjectId("4d2eadffd126330e1e0f989a"), "a" : "test" }> db.a.update({a: "test"}, {foo: "bar"})> db.a.find(){ "_id" : ObjectId("4d2eadffd126330e1e0f989a"), "foo" : "bar" }
![Page 21: MongoDB - assets.astrails.comassets.astrails.com/presentations/database2011/MongoDB-for-SQL-a… · mongo MongoDB shell version: 1.6.5 connecting to: test > help()!db.help() help](https://reader034.vdocuments.site/reader034/viewer/2022050715/5f0c7e3e7e708231d435ad77/html5/thumbnails/21.jpg)
Modifiers
![Page 22: MongoDB - assets.astrails.comassets.astrails.com/presentations/database2011/MongoDB-for-SQL-a… · mongo MongoDB shell version: 1.6.5 connecting to: test > help()!db.help() help](https://reader034.vdocuments.site/reader034/viewer/2022050715/5f0c7e3e7e708231d435ad77/html5/thumbnails/22.jpg)
$set
> db.a.update({"foo": "bar"}, {$set : {bar: "baz"}})> db.a.find(){ "_id" : ObjectId("4d2eadffd126330e1e0f989a"), "bar" : "baz", "foo" : "bar" }
![Page 23: MongoDB - assets.astrails.comassets.astrails.com/presentations/database2011/MongoDB-for-SQL-a… · mongo MongoDB shell version: 1.6.5 connecting to: test > help()!db.help() help](https://reader034.vdocuments.site/reader034/viewer/2022050715/5f0c7e3e7e708231d435ad77/html5/thumbnails/23.jpg)
$inc> db.a.update({"foo": "bar"}, {$inc : {qwe: 1}})> db.a.find(){ "_id" : ObjectId("4d2eadffd126330e1e0f989a"), "bar" : "baz", "foo" : "bar", "qwe" : 1 }
> db.a.update({"foo": "bar"}, {$inc : {qwe: 1}})> db.a.find(){ "_id" : ObjectId("4d2eadffd126330e1e0f989a"), "bar" : "baz", "foo" : "bar", "qwe" : 2 }
![Page 24: MongoDB - assets.astrails.comassets.astrails.com/presentations/database2011/MongoDB-for-SQL-a… · mongo MongoDB shell version: 1.6.5 connecting to: test > help()!db.help() help](https://reader034.vdocuments.site/reader034/viewer/2022050715/5f0c7e3e7e708231d435ad77/html5/thumbnails/24.jpg)
$push> db.b.insert({a: "test"})> db.b.update({a: "test"}, {$push: {foo: "bar"}})> db.b.find(){ "_id" : ObjectId("4d2eb5d0d126330e1e0f989b"), "a" : "test", "foo" : [ "bar" ] }> db.b.update({a: "test"}, {$push: {foo: "baz"}})> db.b.find() { "_id" : ObjectId("4d2eb5d0d126330e1e0f989b"), "a" : "test", "foo" : [ "bar", "baz" ] }
![Page 25: MongoDB - assets.astrails.comassets.astrails.com/presentations/database2011/MongoDB-for-SQL-a… · mongo MongoDB shell version: 1.6.5 connecting to: test > help()!db.help() help](https://reader034.vdocuments.site/reader034/viewer/2022050715/5f0c7e3e7e708231d435ad77/html5/thumbnails/25.jpg)
> db.posts.insert({"title": "mongodb"})> db.posts.update({"title": "mongodb"}, {$push: {comments: {user: "Vitaly", comment: "MongoDB rocks!"}}})> db.posts.update({"title": "mongodb"}, {$push: {comments: {user: "Boris", comment: "Yes, it does!"}}}) > db.posts.find(){ "_id" : ObjectId("4d2eb7bfd126330e1e0f989d"), "comments" : [ { "user" : "Vitaly", "comment" : "MongoDB rocks!" }, { "user" : "Boris", "comment" : "Yes, it does!" }], "title" : "mongodb" }
![Page 26: MongoDB - assets.astrails.comassets.astrails.com/presentations/database2011/MongoDB-for-SQL-a… · mongo MongoDB shell version: 1.6.5 connecting to: test > help()!db.help() help](https://reader034.vdocuments.site/reader034/viewer/2022050715/5f0c7e3e7e708231d435ad77/html5/thumbnails/26.jpg)
> db.posts.insert({_id: 1, title: "test", stats: {pageviews: 0, clicks: 0}})> db.posts.update({_id: 1}, {$inc: {"stats.clicks": 3}})> db.posts.find(){ "_id" : 1, "title" : "test", "stats" : { "pageviews" : 0, "clicks" : 3 } }
![Page 27: MongoDB - assets.astrails.comassets.astrails.com/presentations/database2011/MongoDB-for-SQL-a… · mongo MongoDB shell version: 1.6.5 connecting to: test > help()!db.help() help](https://reader034.vdocuments.site/reader034/viewer/2022050715/5f0c7e3e7e708231d435ad77/html5/thumbnails/27.jpg)
$addToSet
> db.c.insert({a: "test"})> db.c.update({a: "test"}, {$addToSet: {foo: "bar"}})> db.c.update({a: "test"}, {$addToSet: {foo: "baz"}})> db.c.update({a: "test"}, {$addToSet: {foo: "bar"}})> db.c.find(){ "_id" : ObjectId("4d2eb9e4d126330e1e0f989e"), "a" : "test", "foo" : [ "bar", "baz" ] }
![Page 28: MongoDB - assets.astrails.comassets.astrails.com/presentations/database2011/MongoDB-for-SQL-a… · mongo MongoDB shell version: 1.6.5 connecting to: test > help()!db.help() help](https://reader034.vdocuments.site/reader034/viewer/2022050715/5f0c7e3e7e708231d435ad77/html5/thumbnails/28.jpg)
$pop
> db.c.find(){ "_id" : ObjectId("4d2eb9e4d126330e1e0f989e"), "a" : "test", "foo" : [ "bar", "baz" ] }> db.c.update({a: "test"}, {$pop: {foo: 1}})> db.c.find(){ "_id" : ObjectId("4d2eb9e4d126330e1e0f989e"), "a" : "test", "foo" : [ "bar" ] }
![Page 29: MongoDB - assets.astrails.comassets.astrails.com/presentations/database2011/MongoDB-for-SQL-a… · mongo MongoDB shell version: 1.6.5 connecting to: test > help()!db.help() help](https://reader034.vdocuments.site/reader034/viewer/2022050715/5f0c7e3e7e708231d435ad77/html5/thumbnails/29.jpg)
> db.posts.find(){ "_id" : ObjectId("4d2ebf47d126330e1e0f98a0"), "comments" : [ { "user" : "Vitaly", "comment" : "MongoDB rocks!" }, { "user" : "Boris", "comment" : "Yes, it does!" }], "title" : "mongodb" }
![Page 30: MongoDB - assets.astrails.comassets.astrails.com/presentations/database2011/MongoDB-for-SQL-a… · mongo MongoDB shell version: 1.6.5 connecting to: test > help()!db.help() help](https://reader034.vdocuments.site/reader034/viewer/2022050715/5f0c7e3e7e708231d435ad77/html5/thumbnails/30.jpg)
db.posts.update({title: "mongodb"}, {$inc: {"comments.1.rating": 1}})
![Page 31: MongoDB - assets.astrails.comassets.astrails.com/presentations/database2011/MongoDB-for-SQL-a… · mongo MongoDB shell version: 1.6.5 connecting to: test > help()!db.help() help](https://reader034.vdocuments.site/reader034/viewer/2022050715/5f0c7e3e7e708231d435ad77/html5/thumbnails/31.jpg)
> db.posts.find(){ "_id" : ObjectId("4d2ebf47d126330e1e0f98a0"), "comments" : [ { "user" : "Vitaly", "comment" : "MongoDB rocks!" }, { "user" : "Boris", "rating" : 1, "comment" : "Yes, it does!" }], "title" : "mongodb" }
![Page 32: MongoDB - assets.astrails.comassets.astrails.com/presentations/database2011/MongoDB-for-SQL-a… · mongo MongoDB shell version: 1.6.5 connecting to: test > help()!db.help() help](https://reader034.vdocuments.site/reader034/viewer/2022050715/5f0c7e3e7e708231d435ad77/html5/thumbnails/32.jpg)
upsert
> db.d.update({foo: 5}, {$inc: {foo: 1}, $set: {bar: "baz"}}, true)> db.d.find() { "_id" : ObjectId("4d2ec0f6ac41433c1f1c9c31"), "bar" : "baz", "foo" : 6 }
![Page 33: MongoDB - assets.astrails.comassets.astrails.com/presentations/database2011/MongoDB-for-SQL-a… · mongo MongoDB shell version: 1.6.5 connecting to: test > help()!db.help() help](https://reader034.vdocuments.site/reader034/viewer/2022050715/5f0c7e3e7e708231d435ad77/html5/thumbnails/33.jpg)
multi update> db.e.find(){ "_id" : 1, "a" : 2, "b" : 3 }{ "_id" : 2, "a" : 2, "b" : 4 }> db.e.update({a:2}, {$set: {b: 10}})> db.e.find(){ "_id" : 1, "a" : 2, "b" : 10 }{ "_id" : 2, "a" : 2, "b" : 4 }> db.e.update({a:2}, {$set: {b: 20}}, false, true)> db.e.find(){ "_id" : 1, "a" : 2, "b" : 20 }{ "_id" : 2, "a" : 2, "b" : 20 }
![Page 34: MongoDB - assets.astrails.comassets.astrails.com/presentations/database2011/MongoDB-for-SQL-a… · mongo MongoDB shell version: 1.6.5 connecting to: test > help()!db.help() help](https://reader034.vdocuments.site/reader034/viewer/2022050715/5f0c7e3e7e708231d435ad77/html5/thumbnails/34.jpg)
Queries
![Page 35: MongoDB - assets.astrails.comassets.astrails.com/presentations/database2011/MongoDB-for-SQL-a… · mongo MongoDB shell version: 1.6.5 connecting to: test > help()!db.help() help](https://reader034.vdocuments.site/reader034/viewer/2022050715/5f0c7e3e7e708231d435ad77/html5/thumbnails/35.jpg)
partial documents> db.posts.find(){ "_id" : ObjectId("4d2ebf47d126330e1e0f98a0"), "comments" : [ { "user" : "Vitaly", "comment" : "MongoDB rocks!" }, { "comment" : "Yes, it does!", "rating" : 1, "user" : "Boris" }], "title" : "mongodb" }
![Page 36: MongoDB - assets.astrails.comassets.astrails.com/presentations/database2011/MongoDB-for-SQL-a… · mongo MongoDB shell version: 1.6.5 connecting to: test > help()!db.help() help](https://reader034.vdocuments.site/reader034/viewer/2022050715/5f0c7e3e7e708231d435ad77/html5/thumbnails/36.jpg)
partial documents> db.posts.find({}, {title: 1}){ "_id" : ObjectId("4d2ebf47d126330e1e0f98a0"), "title" : "mongodb" }
![Page 37: MongoDB - assets.astrails.comassets.astrails.com/presentations/database2011/MongoDB-for-SQL-a… · mongo MongoDB shell version: 1.6.5 connecting to: test > help()!db.help() help](https://reader034.vdocuments.site/reader034/viewer/2022050715/5f0c7e3e7e708231d435ad77/html5/thumbnails/37.jpg)
partial documents> db.posts.find({}, {title: 0}){ "_id" : ObjectId("4d2ebf47d126330e1e0f98a0"), "comments" : [ { "user" : "Vitaly", "comment" : "MongoDB rocks!" }, { "comment" : "Yes, it does!", "rating" : 1, "user" : "Boris" }] }
![Page 38: MongoDB - assets.astrails.comassets.astrails.com/presentations/database2011/MongoDB-for-SQL-a… · mongo MongoDB shell version: 1.6.5 connecting to: test > help()!db.help() help](https://reader034.vdocuments.site/reader034/viewer/2022050715/5f0c7e3e7e708231d435ad77/html5/thumbnails/38.jpg)
partial documents> db.posts.find({}, {"comments.rating": 1}){ "_id" : ObjectId("4d2ebf47d126330e1e0f98a0"), "comments" : [ { }, { "rating" : 1 } ] }
![Page 39: MongoDB - assets.astrails.comassets.astrails.com/presentations/database2011/MongoDB-for-SQL-a… · mongo MongoDB shell version: 1.6.5 connecting to: test > help()!db.help() help](https://reader034.vdocuments.site/reader034/viewer/2022050715/5f0c7e3e7e708231d435ad77/html5/thumbnails/39.jpg)
conditionals
• $lt - less then
• $gt - greater then
• $lte - less then or equal
• $gte - greater then or equal
![Page 40: MongoDB - assets.astrails.comassets.astrails.com/presentations/database2011/MongoDB-for-SQL-a… · mongo MongoDB shell version: 1.6.5 connecting to: test > help()!db.help() help](https://reader034.vdocuments.site/reader034/viewer/2022050715/5f0c7e3e7e708231d435ad77/html5/thumbnails/40.jpg)
conditionals
db.posts.find({"stats.clicks": {$gte: 0, $lte: 10}})
![Page 41: MongoDB - assets.astrails.comassets.astrails.com/presentations/database2011/MongoDB-for-SQL-a… · mongo MongoDB shell version: 1.6.5 connecting to: test > help()!db.help() help](https://reader034.vdocuments.site/reader034/viewer/2022050715/5f0c7e3e7e708231d435ad77/html5/thumbnails/41.jpg)
Indexes
![Page 42: MongoDB - assets.astrails.comassets.astrails.com/presentations/database2011/MongoDB-for-SQL-a… · mongo MongoDB shell version: 1.6.5 connecting to: test > help()!db.help() help](https://reader034.vdocuments.site/reader034/viewer/2022050715/5f0c7e3e7e708231d435ad77/html5/thumbnails/42.jpg)
db.posts.ensureIndex({"date" : -1, "title": 1})db.posts.ensureIndex({"comments.date" : -1})db.users.ensureIndex({"email": 1}, {"unique": true})
![Page 43: MongoDB - assets.astrails.comassets.astrails.com/presentations/database2011/MongoDB-for-SQL-a… · mongo MongoDB shell version: 1.6.5 connecting to: test > help()!db.help() help](https://reader034.vdocuments.site/reader034/viewer/2022050715/5f0c7e3e7e708231d435ad77/html5/thumbnails/43.jpg)
Geospatial
db.users.ensureIndex({"location" : "2d"})
db.users.find({location: {$near: [10, 20]}})db.users.find({location: {$within: {$box: [[10, 20], [30,40]]}})db.users.find({location: {$within: {$center: [[10, 20], 35]}})
![Page 44: MongoDB - assets.astrails.comassets.astrails.com/presentations/database2011/MongoDB-for-SQL-a… · mongo MongoDB shell version: 1.6.5 connecting to: test > help()!db.help() help](https://reader034.vdocuments.site/reader034/viewer/2022050715/5f0c7e3e7e708231d435ad77/html5/thumbnails/44.jpg)
There is more
• counts
• limits
• sorting
• offsets
• grouping
![Page 45: MongoDB - assets.astrails.comassets.astrails.com/presentations/database2011/MongoDB-for-SQL-a… · mongo MongoDB shell version: 1.6.5 connecting to: test > help()!db.help() help](https://reader034.vdocuments.site/reader034/viewer/2022050715/5f0c7e3e7e708231d435ad77/html5/thumbnails/45.jpg)
Map Reduce
![Page 46: MongoDB - assets.astrails.comassets.astrails.com/presentations/database2011/MongoDB-for-SQL-a… · mongo MongoDB shell version: 1.6.5 connecting to: test > help()!db.help() help](https://reader034.vdocuments.site/reader034/viewer/2022050715/5f0c7e3e7e708231d435ad77/html5/thumbnails/46.jpg)
Replication
![Page 47: MongoDB - assets.astrails.comassets.astrails.com/presentations/database2011/MongoDB-for-SQL-a… · mongo MongoDB shell version: 1.6.5 connecting to: test > help()!db.help() help](https://reader034.vdocuments.site/reader034/viewer/2022050715/5f0c7e3e7e708231d435ad77/html5/thumbnails/47.jpg)
Master Slave
# on the masterdb1> mongod --master
# on the slavedb2> mongod --slave --source db1:10000
![Page 48: MongoDB - assets.astrails.comassets.astrails.com/presentations/database2011/MongoDB-for-SQL-a… · mongo MongoDB shell version: 1.6.5 connecting to: test > help()!db.help() help](https://reader034.vdocuments.site/reader034/viewer/2022050715/5f0c7e3e7e708231d435ad77/html5/thumbnails/48.jpg)
Replica Set
# on the primarydb1> mongod --replSet myset/db2
# on the secondarydb2> mongod --replSet myset/db1
# in a mongo shell:> db.runCommand({"replSetInitiate", {_id: “myset”, ...
![Page 49: MongoDB - assets.astrails.comassets.astrails.com/presentations/database2011/MongoDB-for-SQL-a… · mongo MongoDB shell version: 1.6.5 connecting to: test > help()!db.help() help](https://reader034.vdocuments.site/reader034/viewer/2022050715/5f0c7e3e7e708231d435ad77/html5/thumbnails/49.jpg)
Replication is Asynchronous!
![Page 50: MongoDB - assets.astrails.comassets.astrails.com/presentations/database2011/MongoDB-for-SQL-a… · mongo MongoDB shell version: 1.6.5 connecting to: test > help()!db.help() help](https://reader034.vdocuments.site/reader034/viewer/2022050715/5f0c7e3e7e708231d435ad77/html5/thumbnails/50.jpg)
Sharding
![Page 51: MongoDB - assets.astrails.comassets.astrails.com/presentations/database2011/MongoDB-for-SQL-a… · mongo MongoDB shell version: 1.6.5 connecting to: test > help()!db.help() help](https://reader034.vdocuments.site/reader034/viewer/2022050715/5f0c7e3e7e708231d435ad77/html5/thumbnails/51.jpg)
Sharding# start config serverdb1> .mongod
# start mongoSdb2> mongos --configdb db1
# start a sharddb3> ./mongod
# in a mongo shell connected to mongoS:> db.runCommand({addshard : "db3"})> db.runCommand({enablesharding : "intro"})> db.runCommand({shardcollection : "intro.a", "key" : {_id: 1}})
![Page 52: MongoDB - assets.astrails.comassets.astrails.com/presentations/database2011/MongoDB-for-SQL-a… · mongo MongoDB shell version: 1.6.5 connecting to: test > help()!db.help() help](https://reader034.vdocuments.site/reader034/viewer/2022050715/5f0c7e3e7e708231d435ad77/html5/thumbnails/52.jpg)
MongoDBQ & A
Vitaly Kushnerastrails.com