SlideShare una empresa de Scribd logo
1 de 29
Descargar para leer sin conexión
Zahid Mian
Part of the Brown-bag Series
 Schema-less
 Document DB (don't thinkWord Document)
 Document is a JSON object
 Supports Indexes
 Scalable
 Doesn't Support "traditional" Joins
 Doesn't SupportTransactions (not ACID-compliant)
 Version 3.0.5 (in this doc)
 http://docs.mongodb.org/manual/
 https://www.mongodb.org/downloads
 Dictionaries and Arrays
 {}
 {"fruits": ["apple", "pear", "peach"]}
 {name: "Adam Smith"}
 {numbers: [7,2,3,8]}
 {name: "Adam Smith", hobbies: [hobby: "Econ",
hobby:"Tennis"]}
 Formal Representation: http://json.org/
RDBMS SQL MONGODB
database database
table collection
index index
row document
column field
joining N/A
 mongod (launch server)
 mongo (launch client)
 mongorestore (load a db into mongo)
 use database (within client, use spceific db)
 db.collection.findOne();
 Download/extract mongodb files
 Either update Path to include bin folder or navigate to bin folder …
 Create folder for data …
 > md data -> md datadb (remember where you created this folder)
 > mongod --dbpath c:datadb (default path onWindows)
▪ Now the mongodb server will be running (unless there is a problem)
 From another command shell launch client: > mongo
▪ Now the mongodb shell will be running
▪ Try the following commands:
▪ show databases
▪ db
▪ show collections
 Create - Insert
 Read - Find
 Update - Update
 Delete - Remove
 Everything is a method/API, not as SQL syntax
 Valid: db.names.find()
 Invalid: slect * from names
 javascript interpreter
 > for (i=0;i<3;i++) print("hello");
 > help
 > help keys
 auto complete with tab
 > z = {"a":1}
 > z.a
 > z["a"]
 > x={a:1}; y="a"; x[y]++; print(x.a); // output is 2
 Binary Specification (bsonspec.org)
 Allows storage of extended datatypes
 Date,Timestamp, Double, Integer, etc.
 > obj = {
a:1,
b: ISODate("2015-03-21T17:41:55.325Z", c:},
c: NumberLong(555389),
d: Boolean(true)
}
 > doc = {name: "Brady", age: 38, team: "Patriots"}
 If players collection doesn’t exist, it will create one
 db.players.insert(doc)
 db.players.find()
 "_id" is a unique id created by the database; immutable
 > db.players.findOne() // random document
 > db.players.remove({}) // remove all objects in collection
 > db.players.delete() // remove the entire collection
 > db.players.findOne()
 > db.players.findOne("name": "Brady")
 > db.players.findOne({"name":"Brady", {"_id": false})
 > db.players.findOne({"name":"Brady", {"_id": false, "name": true})
 > db.players.find().pretty() // well-formatted
 > db.players.count("name" : "Brady") // Count of records
 > db.players.find({"name":"Brady", "age": 38}).pretty()
 > db.players.find({"age": {$gt:30} }).pretty() // greater than 30
 > db.players.find({"age": {$lt:40} }).pretty() // less than 40
 > db.players.find({"age": {$gte:30, $lte:40}).pretty() // between 30
and 40
> db.players.find({"name": {$lt: "C"}},
{"_id":false, "name":true})
{ "name" : "Brady" }
{ "name" : "B" }
> db.players.find({"name": {$gt: "B"}}, {"_id":false,
"name":true})
{ "name" : "Brady" }
{ "name" : "brady" }
{ "name" : "Cano" }
{ "name" : "b" }
{ "name" : "brown" }
> db.players.find({"name": {$gt: "b"}}, {"_id":false,
"name":true})
{ "name" : "brady" }
{ "name" : "brown" }
> db.players.find({}, {"_id":false, "name":true})
{ "name" : "Brady" }
{ "name" : "brady" }
{ "name" : "Cano" }
{ "name" : "B" }
{ "name" : "b" }
{ "name" : "brown" }
 > db.players.find({"city": {$exists: true}})
 > db.players.find({"city": {$exists: false}})
 > db.players.find({"name": {$type: 2}}) // BSONTypes Numbers
 docs.mongodb.org/manual/reference/bson-types/
 // find all players with a "w" in the name key
 > db.players.find({name: {$regex: "w"}}, {"_id":false, "name":true})
 // find all players with names ending in "n"
 > db.players.find({name: {$regex: "n$"}}, {"_id":false, "name":true})
 // find all players with names that start with "b"
 > db.players.find({name: {$regex: "^b"}}, {"_id":false, "name":true})
 // find players that have age of 38 OR have a city
 > db.players.find({$or: [{"age":38}, {"city": {$exists:true}}]})
 // find players that have age 38 AND name equals "Brady"
 > db.players.find({$and [{age:38}, {name:"Brady"}]})
 // same as … a bit more efficient
 > db.players.find({age:38, name:"Brady"})
 //What about this?Think about javascript behavior!!
 > db.players.find({age:38, age:40})
 > db.accounts.find()
 {"name" : "Adam", "favs" : [ "ice cream", "pretzels", "chips" ] }
 {"name" : "Mike", "favs" : [ "beer", "chips" ] }
 {"name" : "Sam", "favs" : "chips" }
 > db.accounts.find({favs:"chips"})
 > db.accounts.find({favs:"chips", name: {$gte : "M"}})
 > db.accounts.find({favs: {$all:["chips", "pretzels"]}})
 > db.accounts.find({favs: {$any: ["beer", "pretzels"]}})
> db.users.find().pretty()
{
"_id" :
ObjectId("55ca69a88b9e931abe0295db"),
"name" : "Adam",
"email" : {
"work" : "abc@dddd1.com",
"personal" : "abc2@dkjdkd.com"
}
}
{
"_id" : ObjectId("55ca6a318b9e931abe0295dc"),
"name" : "zahid",
"email" : {
"work" : "abc@eeeee2.com",
"personal" : "abc3@dkjdkd.com"
}
}
> db.users.find({"email.work": {$regex:"dddd"
}}).pretty()
{
"_id" : ObjectId("55ca69a88b9e931abe0295db"),
"name" : "Adam",
"email" : {
"work" : "abc@dddd1.com",
"personal" : "abc2@dkjdkd.com"
}
}
 > cur = db.players.find();
 > cur.hasNext()
 > cur.next()
 > while (cur.hasNext()) printjson(cur.next());
 > cur.limit(5); // nothing is executed until cursor is read
 > cur.sort( {name: -l} ); // negative lexicographical sort
 > cur.sort( {name: -l} ).limit(5); // chaining methods
 > cur.sort( {name: -l} ).limit(5).skip(1) // first sort, then limit,
then skip
> db.players.find({name:"brady"})
{ "_id" : ObjectId("55ca58bf8b9e931abe0295d4"), "name" : "brady", "age" : 40, "team" : "Patriots" }
// update all player documents where name equals "brady" (set age to 42, team to "Broncos")
> db.players.update({name: "brady"}, {age: 42, team:"Broncos"} )
> db.players.find({team:"Broncos"})
{ "_id" : ObjectId("55ca58bf8b9e931abe0295d4"), "age" : 42, "team" : "Broncos" } // name is gone!
> db.players.update({team: "Broncos"}, {name: "brady", age: 42, team:"Patriots"} ) // put name back
> db.players.find({name:"brady"})
{ "_id" : ObjectId("55ca58bf8b9e931abe0295d4"), "name" : "brady", "age" : 42, "team" : "Patriots" }
> db.players.update({name:"brady"},{$set: {age:50}})
> db.players.find({name:"brady"})
{ "_id" : ObjectId("55ca58bf8b9e931abe0295d4"), "name" : "brady", "age" : 50, "team" : "Patriots" }
> db.players.update({name:"brady"},{$unset: {age:1}}
> db.players.find({name:"brady"})
{ "_id" : ObjectId("55ca58bf8b9e931abe0295d4"), "name" : "brady", "team" : "Patriots" }
> db.arrays.insert( {_id: 0, a: [1,2,3,4]})
> db.arrays.find()
{ "_id" : 0, "a" : [ 1, 2, 3, 4 ] }
> db.arrays.update({_id:0}, {$set: {"a.2": 5}})
> db.arrays.find()
{ "_id" : 0, "a" : [ 1, 2, 5, 4 ] }
> db.arrays.update({_id:0}, {$push: {a: 6}})
> db.arrays.find()
{ "_id" : 0, "a" : [ 1, 2, 5, 4, 6 ] }
> db.arrays.update({_id:0}, {$pop: {a: 1}})
> db.arrays.find()
{ "_id" : 0, "a" : [ 1, 2, 5, 4 ] }
> db.arrays.update({_id:0}, {$pop: {a: -1}})
> db.arrays.find()
{ "_id" : 0, "a" : [ 2, 5, 4 ] }
> db.arrays.update({_id:0}, {$pushAll: {a:
[7,8,9]}})
> db.arrays.find()
{ "_id" : 0, "a" : [ 2, 5, 4, 7, 8, 9 ] }
> db.arrays.update({_id:0}, {$pull: {a: 5}})
> db.arrays.update({_id:0}, {$pull: {a: 5}})
> db.arrays.find()
{ "_id" : 0, "a" : [ 2, 4, 7, 8, 9 ] }
> db.arrays.update({_id:0}, {$pullAll: {a:
[8,9]}})
> db.arrays.find()
{ "_id" : 0, "a" : [ 2, 4, 7 ] }
> db.arrays.update({_id:0}, {$addToSet: {a:
3}})
> db.arrays.find()
{ "_id" : 0, "a" : [ 2, 4, 7, 3 ] }
 Combines Update/Insert
 Excellent use case when you don't know if a document already
exists
> db.players.update({name:"Zahid"}, {$set: {age:30, team:
"Patriots"}}, {upsert: true} )
> db.players.find({name:"Zahid"}).pretty()
{
"_id" : ObjectId("55ca7b04f971f0ee874cf2af"),
"name" : "Zahid",
"age" : 30,
"team" : "Patriots"
}
 {} empty document matches every document in collection
 db.players.update({}, {$set : {newcol:10}})
 Above statement will only update one document (the first
one)
 To add newcol to all documents, use the multi option
 db.players.update({}, {$set : {newcol:10}}, {multi: true})
 Concurrency issues
 Transactions are not isolated
 If 10000 updates, possible that 2 different reads could get different
results
 db.players.remove( {name: "brady"})
 db.players.remove({}) // no need for multi option
 db.players.drop() // drop the entire collection; more efficient
 > db.players.ensureIndex({name:1}, {unique:true}) // ensure
unique index on name
 > db.players.ensureIndex({name:1, age:1}) // compound index
on name and age
 > db.players.getIndexes() // retrieves a list of all indexes on
players collections
 > db.players.getIndexSize() // number of bytes allocated to
indexes
 > db.players.reIndex()
 count
 distinct
 group
> db.records.group( {
key: { a: 1 },
cond: { a: { $lt: 3 } },
reduce: function(cur, result) {
result.count += cur.count },
initial: { count: 0 }
} )
> db.grades.findOne()
{
"_id" : ObjectId("50906d7fa3c412bb040eb577"),
"student_id" : 0,
"type" : "exam",
"score" : 54.6535436362647
}
// sql: selectTop 1 student_id _id, avg(score) average from grades group by student_id order by avg(score) desc
> db.grades.aggregate(
{'$group':{'_id':'$student_id', 'average':{$avg:'$score'}}},
{'$sort':{'average':-1}},
{'$limit':1})
// select student_id _id, min(score) min from grades where score >= 65 group by student_id order by min(score)
> db.grades.aggregate([
{ $match : { score : {$gte : 65 } } },
{ '$group': {'_id':'$student_id', 'min': { $min:'$score'} } },
{ '$sort': { 'min': 1 } } ] );
 $bit - performs bitwise AND, OR, and XOR updates on integer values
 $mod - performs a modulo operation on the value of a field
 $not - returns documents that do not match query expression
 $nor - returns documents that fail to match both clauses (as in "neither/nor")
 Geospatial methods like $geoWithin, $geoIntersects, $near, $nearSphere
 $hint - forces the query optimizer to use specific index
 db.collection.find().explain() // retrieve query execution plan
 $maxTimeMS - specifies maximum time for execution of query
 $natural - sort documents by natural order (ordering of documents internally
within database)
 $project - reshapes each document in the stream (adding new fields or removing
fields)
 $cmp, $eq, $gt, $gte, $lt, $lte, $ne (equality operators)
MongoD Essentials

Más contenido relacionado

La actualidad más candente

MongoDB .local London 2019: Tips and Tricks++ for Querying and Indexing MongoDB
MongoDB .local London 2019: Tips and Tricks++ for Querying and Indexing MongoDBMongoDB .local London 2019: Tips and Tricks++ for Querying and Indexing MongoDB
MongoDB .local London 2019: Tips and Tricks++ for Querying and Indexing MongoDBMongoDB
 
Storing tree structures with MongoDB
Storing tree structures with MongoDBStoring tree structures with MongoDB
Storing tree structures with MongoDBVyacheslav
 
Mapping Flatland: Using MongoDB for an MMO Crossword Game (GDC Online 2011)
Mapping Flatland: Using MongoDB for an MMO Crossword Game (GDC Online 2011)Mapping Flatland: Using MongoDB for an MMO Crossword Game (GDC Online 2011)
Mapping Flatland: Using MongoDB for an MMO Crossword Game (GDC Online 2011)Grant Goodale
 
From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)Night Sailer
 
Webinar: Strongly Typed Languages and Flexible Schemas
Webinar: Strongly Typed Languages and Flexible SchemasWebinar: Strongly Typed Languages and Flexible Schemas
Webinar: Strongly Typed Languages and Flexible SchemasMongoDB
 
Strongly Typed Languages and Flexible Schemas
Strongly Typed Languages and Flexible SchemasStrongly Typed Languages and Flexible Schemas
Strongly Typed Languages and Flexible SchemasNorberto Leite
 
Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)
Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)
Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)MongoSF
 
MongoDB World 2016: Deciphering .explain() Output
MongoDB World 2016: Deciphering .explain() OutputMongoDB World 2016: Deciphering .explain() Output
MongoDB World 2016: Deciphering .explain() OutputMongoDB
 
4시간만에 따라해보는 Windows 10 앱 개발 샘플코드
4시간만에 따라해보는 Windows 10 앱 개발 샘플코드4시간만에 따라해보는 Windows 10 앱 개발 샘플코드
4시간만에 따라해보는 Windows 10 앱 개발 샘플코드영욱 김
 
Modern Application Foundations: Underscore and Twitter Bootstrap
Modern Application Foundations: Underscore and Twitter BootstrapModern Application Foundations: Underscore and Twitter Bootstrap
Modern Application Foundations: Underscore and Twitter BootstrapHoward Lewis Ship
 
2011 Mongo FR - Indexing in MongoDB
2011 Mongo FR - Indexing in MongoDB2011 Mongo FR - Indexing in MongoDB
2011 Mongo FR - Indexing in MongoDBantoinegirbal
 
Indexing and Query Optimization
Indexing and Query OptimizationIndexing and Query Optimization
Indexing and Query OptimizationMongoDB
 
How to win $10m - analysing DOTA2 data in R (Sheffield R Users Group - May)
How to win $10m - analysing DOTA2 data in R (Sheffield R Users Group - May)How to win $10m - analysing DOTA2 data in R (Sheffield R Users Group - May)
How to win $10m - analysing DOTA2 data in R (Sheffield R Users Group - May)Paul Richards
 
Building DSLs with Groovy
Building DSLs with GroovyBuilding DSLs with Groovy
Building DSLs with GroovySten Anderson
 
Building a Scalable Inbox System with MongoDB and Java
Building a Scalable Inbox System with MongoDB and JavaBuilding a Scalable Inbox System with MongoDB and Java
Building a Scalable Inbox System with MongoDB and Javaantoinegirbal
 

La actualidad más candente (18)

MongoDB .local London 2019: Tips and Tricks++ for Querying and Indexing MongoDB
MongoDB .local London 2019: Tips and Tricks++ for Querying and Indexing MongoDBMongoDB .local London 2019: Tips and Tricks++ for Querying and Indexing MongoDB
MongoDB .local London 2019: Tips and Tricks++ for Querying and Indexing MongoDB
 
Advanced MongoDB #1
Advanced MongoDB #1Advanced MongoDB #1
Advanced MongoDB #1
 
Storing tree structures with MongoDB
Storing tree structures with MongoDBStoring tree structures with MongoDB
Storing tree structures with MongoDB
 
php plus mysql
php plus mysqlphp plus mysql
php plus mysql
 
Mapping Flatland: Using MongoDB for an MMO Crossword Game (GDC Online 2011)
Mapping Flatland: Using MongoDB for an MMO Crossword Game (GDC Online 2011)Mapping Flatland: Using MongoDB for an MMO Crossword Game (GDC Online 2011)
Mapping Flatland: Using MongoDB for an MMO Crossword Game (GDC Online 2011)
 
From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)
 
Webinar: Strongly Typed Languages and Flexible Schemas
Webinar: Strongly Typed Languages and Flexible SchemasWebinar: Strongly Typed Languages and Flexible Schemas
Webinar: Strongly Typed Languages and Flexible Schemas
 
Strongly Typed Languages and Flexible Schemas
Strongly Typed Languages and Flexible SchemasStrongly Typed Languages and Flexible Schemas
Strongly Typed Languages and Flexible Schemas
 
Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)
Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)
Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)
 
MongoDB World 2016: Deciphering .explain() Output
MongoDB World 2016: Deciphering .explain() OutputMongoDB World 2016: Deciphering .explain() Output
MongoDB World 2016: Deciphering .explain() Output
 
Mongo db presentation
Mongo db presentationMongo db presentation
Mongo db presentation
 
4시간만에 따라해보는 Windows 10 앱 개발 샘플코드
4시간만에 따라해보는 Windows 10 앱 개발 샘플코드4시간만에 따라해보는 Windows 10 앱 개발 샘플코드
4시간만에 따라해보는 Windows 10 앱 개발 샘플코드
 
Modern Application Foundations: Underscore and Twitter Bootstrap
Modern Application Foundations: Underscore and Twitter BootstrapModern Application Foundations: Underscore and Twitter Bootstrap
Modern Application Foundations: Underscore and Twitter Bootstrap
 
2011 Mongo FR - Indexing in MongoDB
2011 Mongo FR - Indexing in MongoDB2011 Mongo FR - Indexing in MongoDB
2011 Mongo FR - Indexing in MongoDB
 
Indexing and Query Optimization
Indexing and Query OptimizationIndexing and Query Optimization
Indexing and Query Optimization
 
How to win $10m - analysing DOTA2 data in R (Sheffield R Users Group - May)
How to win $10m - analysing DOTA2 data in R (Sheffield R Users Group - May)How to win $10m - analysing DOTA2 data in R (Sheffield R Users Group - May)
How to win $10m - analysing DOTA2 data in R (Sheffield R Users Group - May)
 
Building DSLs with Groovy
Building DSLs with GroovyBuilding DSLs with Groovy
Building DSLs with Groovy
 
Building a Scalable Inbox System with MongoDB and Java
Building a Scalable Inbox System with MongoDB and JavaBuilding a Scalable Inbox System with MongoDB and Java
Building a Scalable Inbox System with MongoDB and Java
 

Destacado (11)

Pdf almas
Pdf almasPdf almas
Pdf almas
 
Mongo db basics
Mongo db basicsMongo db basics
Mongo db basics
 
Mongo db
Mongo dbMongo db
Mongo db
 
Connecting NodeJS & MongoDB
Connecting NodeJS & MongoDBConnecting NodeJS & MongoDB
Connecting NodeJS & MongoDB
 
MongoDB for Beginners
MongoDB for BeginnersMongoDB for Beginners
MongoDB for Beginners
 
Mongo DB
Mongo DBMongo DB
Mongo DB
 
Intro to NoSQL and MongoDB
Intro to NoSQL and MongoDBIntro to NoSQL and MongoDB
Intro to NoSQL and MongoDB
 
Mongo db
Mongo dbMongo db
Mongo db
 
Mongo DB
Mongo DBMongo DB
Mongo DB
 
Intro To MongoDB
Intro To MongoDBIntro To MongoDB
Intro To MongoDB
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 

Similar a MongoD Essentials

Webinar: General Technical Overview of MongoDB for Dev Teams
Webinar: General Technical Overview of MongoDB for Dev TeamsWebinar: General Technical Overview of MongoDB for Dev Teams
Webinar: General Technical Overview of MongoDB for Dev TeamsMongoDB
 
San Francisco Java User Group
San Francisco Java User GroupSan Francisco Java User Group
San Francisco Java User Groupkchodorow
 
MongoDB World 2019: Using Client Side Encryption in MongoDB 4.2 Link
MongoDB World 2019: Using Client Side Encryption in MongoDB 4.2 LinkMongoDB World 2019: Using Client Side Encryption in MongoDB 4.2 Link
MongoDB World 2019: Using Client Side Encryption in MongoDB 4.2 LinkMongoDB
 
NDC London 2013 - Mongo db for c# developers
NDC London 2013 - Mongo db for c# developersNDC London 2013 - Mongo db for c# developers
NDC London 2013 - Mongo db for c# developersSimon Elliston Ball
 
Schema Design with MongoDB
Schema Design with MongoDBSchema Design with MongoDB
Schema Design with MongoDBrogerbodamer
 
MongoDB全機能解説2
MongoDB全機能解説2MongoDB全機能解説2
MongoDB全機能解説2Takahiro Inoue
 
Mongo db basic installation
Mongo db basic installationMongo db basic installation
Mongo db basic installationKishor Parkhe
 
MongoDB .local Houston 2019: Using Client Side Encryption in MongoDB 4.2
MongoDB .local Houston 2019: Using Client Side Encryption in MongoDB 4.2MongoDB .local Houston 2019: Using Client Side Encryption in MongoDB 4.2
MongoDB .local Houston 2019: Using Client Side Encryption in MongoDB 4.2MongoDB
 
2013-03-23 - NoSQL Spartakiade
2013-03-23 - NoSQL Spartakiade2013-03-23 - NoSQL Spartakiade
2013-03-23 - NoSQL SpartakiadeJohannes Hoppe
 
Tips and Tricks for Avoiding Common Query Pitfalls
Tips and Tricks for Avoiding Common Query PitfallsTips and Tricks for Avoiding Common Query Pitfalls
Tips and Tricks for Avoiding Common Query PitfallsMongoDB
 
10gen Presents Schema Design and Data Modeling
10gen Presents Schema Design and Data Modeling10gen Presents Schema Design and Data Modeling
10gen Presents Schema Design and Data ModelingDATAVERSITY
 
Schema Design
Schema DesignSchema Design
Schema DesignMongoDB
 
Inside PyMongo - MongoNYC
Inside PyMongo - MongoNYCInside PyMongo - MongoNYC
Inside PyMongo - MongoNYCMike Dirolf
 
MongoDB World 2018: Keynote
MongoDB World 2018: KeynoteMongoDB World 2018: Keynote
MongoDB World 2018: KeynoteMongoDB
 
Spark Dataframe - Mr. Jyotiska
Spark Dataframe - Mr. JyotiskaSpark Dataframe - Mr. Jyotiska
Spark Dataframe - Mr. JyotiskaSigmoid
 

Similar a MongoD Essentials (20)

MongoDB
MongoDB MongoDB
MongoDB
 
Webinar: General Technical Overview of MongoDB for Dev Teams
Webinar: General Technical Overview of MongoDB for Dev TeamsWebinar: General Technical Overview of MongoDB for Dev Teams
Webinar: General Technical Overview of MongoDB for Dev Teams
 
San Francisco Java User Group
San Francisco Java User GroupSan Francisco Java User Group
San Francisco Java User Group
 
MongoDB World 2019: Using Client Side Encryption in MongoDB 4.2 Link
MongoDB World 2019: Using Client Side Encryption in MongoDB 4.2 LinkMongoDB World 2019: Using Client Side Encryption in MongoDB 4.2 Link
MongoDB World 2019: Using Client Side Encryption in MongoDB 4.2 Link
 
Mongo db for c# developers
Mongo db for c# developersMongo db for c# developers
Mongo db for c# developers
 
NDC London 2013 - Mongo db for c# developers
NDC London 2013 - Mongo db for c# developersNDC London 2013 - Mongo db for c# developers
NDC London 2013 - Mongo db for c# developers
 
Latinoware
LatinowareLatinoware
Latinoware
 
Mongo DB 102
Mongo DB 102Mongo DB 102
Mongo DB 102
 
MongoDB-SESSION03
MongoDB-SESSION03MongoDB-SESSION03
MongoDB-SESSION03
 
Schema Design with MongoDB
Schema Design with MongoDBSchema Design with MongoDB
Schema Design with MongoDB
 
MongoDB全機能解説2
MongoDB全機能解説2MongoDB全機能解説2
MongoDB全機能解説2
 
Mongo db basic installation
Mongo db basic installationMongo db basic installation
Mongo db basic installation
 
MongoDB .local Houston 2019: Using Client Side Encryption in MongoDB 4.2
MongoDB .local Houston 2019: Using Client Side Encryption in MongoDB 4.2MongoDB .local Houston 2019: Using Client Side Encryption in MongoDB 4.2
MongoDB .local Houston 2019: Using Client Side Encryption in MongoDB 4.2
 
2013-03-23 - NoSQL Spartakiade
2013-03-23 - NoSQL Spartakiade2013-03-23 - NoSQL Spartakiade
2013-03-23 - NoSQL Spartakiade
 
Tips and Tricks for Avoiding Common Query Pitfalls
Tips and Tricks for Avoiding Common Query PitfallsTips and Tricks for Avoiding Common Query Pitfalls
Tips and Tricks for Avoiding Common Query Pitfalls
 
10gen Presents Schema Design and Data Modeling
10gen Presents Schema Design and Data Modeling10gen Presents Schema Design and Data Modeling
10gen Presents Schema Design and Data Modeling
 
Schema Design
Schema DesignSchema Design
Schema Design
 
Inside PyMongo - MongoNYC
Inside PyMongo - MongoNYCInside PyMongo - MongoNYC
Inside PyMongo - MongoNYC
 
MongoDB World 2018: Keynote
MongoDB World 2018: KeynoteMongoDB World 2018: Keynote
MongoDB World 2018: Keynote
 
Spark Dataframe - Mr. Jyotiska
Spark Dataframe - Mr. JyotiskaSpark Dataframe - Mr. Jyotiska
Spark Dataframe - Mr. Jyotiska
 

Más de zahid-mian

Mongodb Aggregation Pipeline
Mongodb Aggregation PipelineMongodb Aggregation Pipeline
Mongodb Aggregation Pipelinezahid-mian
 
Hadoop Technologies
Hadoop TechnologiesHadoop Technologies
Hadoop Technologieszahid-mian
 
Intro to modern cryptography
Intro to modern cryptographyIntro to modern cryptography
Intro to modern cryptographyzahid-mian
 
Hadoop M/R Pig Hive
Hadoop M/R Pig HiveHadoop M/R Pig Hive
Hadoop M/R Pig Hivezahid-mian
 
NoSQL Databases
NoSQL DatabasesNoSQL Databases
NoSQL Databaseszahid-mian
 
Statistics101: Numerical Measures
Statistics101: Numerical MeasuresStatistics101: Numerical Measures
Statistics101: Numerical Measureszahid-mian
 
Amazon SimpleDB
Amazon SimpleDBAmazon SimpleDB
Amazon SimpleDBzahid-mian
 
C# 6 New Features
C# 6 New FeaturesC# 6 New Features
C# 6 New Featureszahid-mian
 
Introduction to d3js (and SVG)
Introduction to d3js (and SVG)Introduction to d3js (and SVG)
Introduction to d3js (and SVG)zahid-mian
 

Más de zahid-mian (9)

Mongodb Aggregation Pipeline
Mongodb Aggregation PipelineMongodb Aggregation Pipeline
Mongodb Aggregation Pipeline
 
Hadoop Technologies
Hadoop TechnologiesHadoop Technologies
Hadoop Technologies
 
Intro to modern cryptography
Intro to modern cryptographyIntro to modern cryptography
Intro to modern cryptography
 
Hadoop M/R Pig Hive
Hadoop M/R Pig HiveHadoop M/R Pig Hive
Hadoop M/R Pig Hive
 
NoSQL Databases
NoSQL DatabasesNoSQL Databases
NoSQL Databases
 
Statistics101: Numerical Measures
Statistics101: Numerical MeasuresStatistics101: Numerical Measures
Statistics101: Numerical Measures
 
Amazon SimpleDB
Amazon SimpleDBAmazon SimpleDB
Amazon SimpleDB
 
C# 6 New Features
C# 6 New FeaturesC# 6 New Features
C# 6 New Features
 
Introduction to d3js (and SVG)
Introduction to d3js (and SVG)Introduction to d3js (and SVG)
Introduction to d3js (and SVG)
 

Último

Call Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night StandCall Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night Standamitlee9823
 
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...amitlee9823
 
Call Girls In Attibele ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Attibele ☎ 7737669865 🥵 Book Your One night StandCall Girls In Attibele ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Attibele ☎ 7737669865 🥵 Book Your One night Standamitlee9823
 
➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men 🔝Bangalore🔝 Esc...
➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men  🔝Bangalore🔝   Esc...➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men  🔝Bangalore🔝   Esc...
➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men 🔝Bangalore🔝 Esc...amitlee9823
 
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...amitlee9823
 
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...SUHANI PANDEY
 
Just Call Vip call girls Palakkad Escorts ☎️9352988975 Two shot with one girl...
Just Call Vip call girls Palakkad Escorts ☎️9352988975 Two shot with one girl...Just Call Vip call girls Palakkad Escorts ☎️9352988975 Two shot with one girl...
Just Call Vip call girls Palakkad Escorts ☎️9352988975 Two shot with one girl...gajnagarg
 
👉 Amritsar Call Girl 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Phone No Amri...
👉 Amritsar Call Girl 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Phone No Amri...👉 Amritsar Call Girl 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Phone No Amri...
👉 Amritsar Call Girl 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Phone No Amri...karishmasinghjnh
 
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...amitlee9823
 
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
➥🔝 7737669865 🔝▻ Mathura Call-girls in Women Seeking Men 🔝Mathura🔝 Escorts...
➥🔝 7737669865 🔝▻ Mathura Call-girls in Women Seeking Men  🔝Mathura🔝   Escorts...➥🔝 7737669865 🔝▻ Mathura Call-girls in Women Seeking Men  🔝Mathura🔝   Escorts...
➥🔝 7737669865 🔝▻ Mathura Call-girls in Women Seeking Men 🔝Mathura🔝 Escorts...amitlee9823
 
Call Girls In Nandini Layout ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Nandini Layout ☎ 7737669865 🥵 Book Your One night StandCall Girls In Nandini Layout ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Nandini Layout ☎ 7737669865 🥵 Book Your One night Standamitlee9823
 
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night StandCall Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Standamitlee9823
 
5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed
5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed
5CL-ADBA,5cladba, Chinese supplier, safety is guaranteedamy56318795
 
➥🔝 7737669865 🔝▻ Dindigul Call-girls in Women Seeking Men 🔝Dindigul🔝 Escor...
➥🔝 7737669865 🔝▻ Dindigul Call-girls in Women Seeking Men  🔝Dindigul🔝   Escor...➥🔝 7737669865 🔝▻ Dindigul Call-girls in Women Seeking Men  🔝Dindigul🔝   Escor...
➥🔝 7737669865 🔝▻ Dindigul Call-girls in Women Seeking Men 🔝Dindigul🔝 Escor...amitlee9823
 
Discover Why Less is More in B2B Research
Discover Why Less is More in B2B ResearchDiscover Why Less is More in B2B Research
Discover Why Less is More in B2B Researchmichael115558
 

Último (20)

Call Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night StandCall Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night Stand
 
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
 
Call Girls In Attibele ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Attibele ☎ 7737669865 🥵 Book Your One night StandCall Girls In Attibele ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Attibele ☎ 7737669865 🥵 Book Your One night Stand
 
➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men 🔝Bangalore🔝 Esc...
➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men  🔝Bangalore🔝   Esc...➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men  🔝Bangalore🔝   Esc...
➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men 🔝Bangalore🔝 Esc...
 
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
 
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get CytotecAbortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
 
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
 
Just Call Vip call girls Palakkad Escorts ☎️9352988975 Two shot with one girl...
Just Call Vip call girls Palakkad Escorts ☎️9352988975 Two shot with one girl...Just Call Vip call girls Palakkad Escorts ☎️9352988975 Two shot with one girl...
Just Call Vip call girls Palakkad Escorts ☎️9352988975 Two shot with one girl...
 
👉 Amritsar Call Girl 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Phone No Amri...
👉 Amritsar Call Girl 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Phone No Amri...👉 Amritsar Call Girl 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Phone No Amri...
👉 Amritsar Call Girl 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Phone No Amri...
 
CHEAP Call Girls in Rabindra Nagar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Rabindra Nagar  (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Rabindra Nagar  (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Rabindra Nagar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
 
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
➥🔝 7737669865 🔝▻ Mathura Call-girls in Women Seeking Men 🔝Mathura🔝 Escorts...
➥🔝 7737669865 🔝▻ Mathura Call-girls in Women Seeking Men  🔝Mathura🔝   Escorts...➥🔝 7737669865 🔝▻ Mathura Call-girls in Women Seeking Men  🔝Mathura🔝   Escorts...
➥🔝 7737669865 🔝▻ Mathura Call-girls in Women Seeking Men 🔝Mathura🔝 Escorts...
 
Call Girls In Nandini Layout ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Nandini Layout ☎ 7737669865 🥵 Book Your One night StandCall Girls In Nandini Layout ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Nandini Layout ☎ 7737669865 🥵 Book Your One night Stand
 
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night StandCall Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Stand
 
5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed
5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed
5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed
 
Abortion pills in Jeddah | +966572737505 | Get Cytotec
Abortion pills in Jeddah | +966572737505 | Get CytotecAbortion pills in Jeddah | +966572737505 | Get Cytotec
Abortion pills in Jeddah | +966572737505 | Get Cytotec
 
➥🔝 7737669865 🔝▻ Dindigul Call-girls in Women Seeking Men 🔝Dindigul🔝 Escor...
➥🔝 7737669865 🔝▻ Dindigul Call-girls in Women Seeking Men  🔝Dindigul🔝   Escor...➥🔝 7737669865 🔝▻ Dindigul Call-girls in Women Seeking Men  🔝Dindigul🔝   Escor...
➥🔝 7737669865 🔝▻ Dindigul Call-girls in Women Seeking Men 🔝Dindigul🔝 Escor...
 
Discover Why Less is More in B2B Research
Discover Why Less is More in B2B ResearchDiscover Why Less is More in B2B Research
Discover Why Less is More in B2B Research
 
CHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 

MongoD Essentials

  • 1. Zahid Mian Part of the Brown-bag Series
  • 2.  Schema-less  Document DB (don't thinkWord Document)  Document is a JSON object  Supports Indexes  Scalable  Doesn't Support "traditional" Joins  Doesn't SupportTransactions (not ACID-compliant)  Version 3.0.5 (in this doc)  http://docs.mongodb.org/manual/  https://www.mongodb.org/downloads
  • 3.  Dictionaries and Arrays  {}  {"fruits": ["apple", "pear", "peach"]}  {name: "Adam Smith"}  {numbers: [7,2,3,8]}  {name: "Adam Smith", hobbies: [hobby: "Econ", hobby:"Tennis"]}  Formal Representation: http://json.org/
  • 4. RDBMS SQL MONGODB database database table collection index index row document column field joining N/A
  • 5.  mongod (launch server)  mongo (launch client)  mongorestore (load a db into mongo)  use database (within client, use spceific db)  db.collection.findOne();
  • 6.  Download/extract mongodb files  Either update Path to include bin folder or navigate to bin folder …  Create folder for data …  > md data -> md datadb (remember where you created this folder)  > mongod --dbpath c:datadb (default path onWindows) ▪ Now the mongodb server will be running (unless there is a problem)  From another command shell launch client: > mongo ▪ Now the mongodb shell will be running ▪ Try the following commands: ▪ show databases ▪ db ▪ show collections
  • 7.  Create - Insert  Read - Find  Update - Update  Delete - Remove  Everything is a method/API, not as SQL syntax  Valid: db.names.find()  Invalid: slect * from names
  • 8.  javascript interpreter  > for (i=0;i<3;i++) print("hello");  > help  > help keys  auto complete with tab  > z = {"a":1}  > z.a  > z["a"]  > x={a:1}; y="a"; x[y]++; print(x.a); // output is 2
  • 9.  Binary Specification (bsonspec.org)  Allows storage of extended datatypes  Date,Timestamp, Double, Integer, etc.  > obj = { a:1, b: ISODate("2015-03-21T17:41:55.325Z", c:}, c: NumberLong(555389), d: Boolean(true) }
  • 10.  > doc = {name: "Brady", age: 38, team: "Patriots"}  If players collection doesn’t exist, it will create one  db.players.insert(doc)  db.players.find()  "_id" is a unique id created by the database; immutable  > db.players.findOne() // random document  > db.players.remove({}) // remove all objects in collection  > db.players.delete() // remove the entire collection
  • 11.
  • 12.  > db.players.findOne()  > db.players.findOne("name": "Brady")  > db.players.findOne({"name":"Brady", {"_id": false})  > db.players.findOne({"name":"Brady", {"_id": false, "name": true})  > db.players.find().pretty() // well-formatted  > db.players.count("name" : "Brady") // Count of records  > db.players.find({"name":"Brady", "age": 38}).pretty()  > db.players.find({"age": {$gt:30} }).pretty() // greater than 30  > db.players.find({"age": {$lt:40} }).pretty() // less than 40  > db.players.find({"age": {$gte:30, $lte:40}).pretty() // between 30 and 40
  • 13. > db.players.find({"name": {$lt: "C"}}, {"_id":false, "name":true}) { "name" : "Brady" } { "name" : "B" } > db.players.find({"name": {$gt: "B"}}, {"_id":false, "name":true}) { "name" : "Brady" } { "name" : "brady" } { "name" : "Cano" } { "name" : "b" } { "name" : "brown" } > db.players.find({"name": {$gt: "b"}}, {"_id":false, "name":true}) { "name" : "brady" } { "name" : "brown" } > db.players.find({}, {"_id":false, "name":true}) { "name" : "Brady" } { "name" : "brady" } { "name" : "Cano" } { "name" : "B" } { "name" : "b" } { "name" : "brown" }
  • 14.  > db.players.find({"city": {$exists: true}})  > db.players.find({"city": {$exists: false}})  > db.players.find({"name": {$type: 2}}) // BSONTypes Numbers  docs.mongodb.org/manual/reference/bson-types/  // find all players with a "w" in the name key  > db.players.find({name: {$regex: "w"}}, {"_id":false, "name":true})  // find all players with names ending in "n"  > db.players.find({name: {$regex: "n$"}}, {"_id":false, "name":true})  // find all players with names that start with "b"  > db.players.find({name: {$regex: "^b"}}, {"_id":false, "name":true})
  • 15.  // find players that have age of 38 OR have a city  > db.players.find({$or: [{"age":38}, {"city": {$exists:true}}]})  // find players that have age 38 AND name equals "Brady"  > db.players.find({$and [{age:38}, {name:"Brady"}]})  // same as … a bit more efficient  > db.players.find({age:38, name:"Brady"})  //What about this?Think about javascript behavior!!  > db.players.find({age:38, age:40})
  • 16.  > db.accounts.find()  {"name" : "Adam", "favs" : [ "ice cream", "pretzels", "chips" ] }  {"name" : "Mike", "favs" : [ "beer", "chips" ] }  {"name" : "Sam", "favs" : "chips" }  > db.accounts.find({favs:"chips"})  > db.accounts.find({favs:"chips", name: {$gte : "M"}})  > db.accounts.find({favs: {$all:["chips", "pretzels"]}})  > db.accounts.find({favs: {$any: ["beer", "pretzels"]}})
  • 17. > db.users.find().pretty() { "_id" : ObjectId("55ca69a88b9e931abe0295db"), "name" : "Adam", "email" : { "work" : "abc@dddd1.com", "personal" : "abc2@dkjdkd.com" } } { "_id" : ObjectId("55ca6a318b9e931abe0295dc"), "name" : "zahid", "email" : { "work" : "abc@eeeee2.com", "personal" : "abc3@dkjdkd.com" } } > db.users.find({"email.work": {$regex:"dddd" }}).pretty() { "_id" : ObjectId("55ca69a88b9e931abe0295db"), "name" : "Adam", "email" : { "work" : "abc@dddd1.com", "personal" : "abc2@dkjdkd.com" } }
  • 18.  > cur = db.players.find();  > cur.hasNext()  > cur.next()  > while (cur.hasNext()) printjson(cur.next());  > cur.limit(5); // nothing is executed until cursor is read  > cur.sort( {name: -l} ); // negative lexicographical sort  > cur.sort( {name: -l} ).limit(5); // chaining methods  > cur.sort( {name: -l} ).limit(5).skip(1) // first sort, then limit, then skip
  • 19. > db.players.find({name:"brady"}) { "_id" : ObjectId("55ca58bf8b9e931abe0295d4"), "name" : "brady", "age" : 40, "team" : "Patriots" } // update all player documents where name equals "brady" (set age to 42, team to "Broncos") > db.players.update({name: "brady"}, {age: 42, team:"Broncos"} ) > db.players.find({team:"Broncos"}) { "_id" : ObjectId("55ca58bf8b9e931abe0295d4"), "age" : 42, "team" : "Broncos" } // name is gone! > db.players.update({team: "Broncos"}, {name: "brady", age: 42, team:"Patriots"} ) // put name back > db.players.find({name:"brady"}) { "_id" : ObjectId("55ca58bf8b9e931abe0295d4"), "name" : "brady", "age" : 42, "team" : "Patriots" } > db.players.update({name:"brady"},{$set: {age:50}}) > db.players.find({name:"brady"}) { "_id" : ObjectId("55ca58bf8b9e931abe0295d4"), "name" : "brady", "age" : 50, "team" : "Patriots" } > db.players.update({name:"brady"},{$unset: {age:1}} > db.players.find({name:"brady"}) { "_id" : ObjectId("55ca58bf8b9e931abe0295d4"), "name" : "brady", "team" : "Patriots" }
  • 20. > db.arrays.insert( {_id: 0, a: [1,2,3,4]}) > db.arrays.find() { "_id" : 0, "a" : [ 1, 2, 3, 4 ] } > db.arrays.update({_id:0}, {$set: {"a.2": 5}}) > db.arrays.find() { "_id" : 0, "a" : [ 1, 2, 5, 4 ] } > db.arrays.update({_id:0}, {$push: {a: 6}}) > db.arrays.find() { "_id" : 0, "a" : [ 1, 2, 5, 4, 6 ] } > db.arrays.update({_id:0}, {$pop: {a: 1}}) > db.arrays.find() { "_id" : 0, "a" : [ 1, 2, 5, 4 ] } > db.arrays.update({_id:0}, {$pop: {a: -1}}) > db.arrays.find() { "_id" : 0, "a" : [ 2, 5, 4 ] } > db.arrays.update({_id:0}, {$pushAll: {a: [7,8,9]}}) > db.arrays.find() { "_id" : 0, "a" : [ 2, 5, 4, 7, 8, 9 ] } > db.arrays.update({_id:0}, {$pull: {a: 5}}) > db.arrays.update({_id:0}, {$pull: {a: 5}}) > db.arrays.find() { "_id" : 0, "a" : [ 2, 4, 7, 8, 9 ] } > db.arrays.update({_id:0}, {$pullAll: {a: [8,9]}}) > db.arrays.find() { "_id" : 0, "a" : [ 2, 4, 7 ] } > db.arrays.update({_id:0}, {$addToSet: {a: 3}}) > db.arrays.find() { "_id" : 0, "a" : [ 2, 4, 7, 3 ] }
  • 21.  Combines Update/Insert  Excellent use case when you don't know if a document already exists > db.players.update({name:"Zahid"}, {$set: {age:30, team: "Patriots"}}, {upsert: true} ) > db.players.find({name:"Zahid"}).pretty() { "_id" : ObjectId("55ca7b04f971f0ee874cf2af"), "name" : "Zahid", "age" : 30, "team" : "Patriots" }
  • 22.  {} empty document matches every document in collection  db.players.update({}, {$set : {newcol:10}})  Above statement will only update one document (the first one)  To add newcol to all documents, use the multi option  db.players.update({}, {$set : {newcol:10}}, {multi: true})  Concurrency issues  Transactions are not isolated  If 10000 updates, possible that 2 different reads could get different results
  • 23.  db.players.remove( {name: "brady"})  db.players.remove({}) // no need for multi option  db.players.drop() // drop the entire collection; more efficient
  • 24.  > db.players.ensureIndex({name:1}, {unique:true}) // ensure unique index on name  > db.players.ensureIndex({name:1, age:1}) // compound index on name and age  > db.players.getIndexes() // retrieves a list of all indexes on players collections  > db.players.getIndexSize() // number of bytes allocated to indexes  > db.players.reIndex()
  • 25.  count  distinct  group > db.records.group( { key: { a: 1 }, cond: { a: { $lt: 3 } }, reduce: function(cur, result) { result.count += cur.count }, initial: { count: 0 } } )
  • 26.
  • 27. > db.grades.findOne() { "_id" : ObjectId("50906d7fa3c412bb040eb577"), "student_id" : 0, "type" : "exam", "score" : 54.6535436362647 } // sql: selectTop 1 student_id _id, avg(score) average from grades group by student_id order by avg(score) desc > db.grades.aggregate( {'$group':{'_id':'$student_id', 'average':{$avg:'$score'}}}, {'$sort':{'average':-1}}, {'$limit':1}) // select student_id _id, min(score) min from grades where score >= 65 group by student_id order by min(score) > db.grades.aggregate([ { $match : { score : {$gte : 65 } } }, { '$group': {'_id':'$student_id', 'min': { $min:'$score'} } }, { '$sort': { 'min': 1 } } ] );
  • 28.  $bit - performs bitwise AND, OR, and XOR updates on integer values  $mod - performs a modulo operation on the value of a field  $not - returns documents that do not match query expression  $nor - returns documents that fail to match both clauses (as in "neither/nor")  Geospatial methods like $geoWithin, $geoIntersects, $near, $nearSphere  $hint - forces the query optimizer to use specific index  db.collection.find().explain() // retrieve query execution plan  $maxTimeMS - specifies maximum time for execution of query  $natural - sort documents by natural order (ordering of documents internally within database)  $project - reshapes each document in the stream (adding new fields or removing fields)  $cmp, $eq, $gt, $gte, $lt, $lte, $ne (equality operators)