-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
38 changed files
with
509 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
mkdir mongodbessentials | ||
cd mongodbessentials | ||
mkdir mongod_only | ||
mongod --dbpath mongod_only | ||
mongosh | ||
show databases | ||
db.test.insertOne({"hello": "world"}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
mkdir replica_set_cmdline | ||
cd replica_set_cmdline | ||
openssl rand -base64 755 > keyfile | ||
chmod 400 keyfile | ||
mkdir -p m{1,2,3}/db | ||
mongod --replSet myReplSet --dbpath ./m1/db --logpath ./m1/mongodb.log --port 27017 --fork --keyFile ./keyfile | ||
mongod --replSet myReplSet --dbpath ./m2/db --logpath ./m2/mongodb.log --port 27018 --fork --keyFile ./keyfile | ||
mongod --replSet myReplSet --dbpath ./m3/db --logpath ./m3/mongodb.log --port 27019 --fork --keyFile ./keyfile | ||
mongosh “mongodb://localhost:27017” | ||
rs.initiate() | ||
use admin | ||
db.createUser({user: 'naomi', pwd: passwordPrompt(), roles: ["root"]}) | ||
db.getSiblingDB("admin").auth("naomi", passwordPrompt()) | ||
rs.add("localhost:27018") | ||
rs.add("localhost:27019") | ||
rs.status() | ||
db.serverStatus()['repl'] | ||
rm -rf mongodbessentials |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
mkdir replicaset | ||
cd replicaset | ||
openssl rand -base64 755 > keyfile | ||
chmod 400 keyfile | ||
mkdir -p m{1,2,3}/db | ||
touch m1.conf | ||
cp m1.conf m2.conf | ||
cp m1.conf m3.conf | ||
mongod -f m1.conf | ||
mongod -f m2.conf | ||
mongod -f m3.conf | ||
mongosh | ||
use admin | ||
config = { | ||
_id: "mongodb-essential-rs", | ||
members: [ | ||
{ _id: 0, host: "localhost:27017" }, | ||
{ _id: 1, host: "localhost:27018" }, | ||
{ _id: 2, host: "localhost:27019" } | ||
] | ||
}; | ||
rs.initiate(config) | ||
db.createUser({user: 'naomi', pwd: passwordPrompt(), roles: ["root"]}) | ||
db.getSiblingDB("admin").auth("naomi") | ||
rs.add("localhost:27018") | ||
rs.add("localhost:27019") | ||
rs.status() | ||
db.serverStatus()['repl'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
cd datasets | ||
mongoimport --username="naomi" --authenticationDatabase="admin" --db=sample_data inventory.json | ||
mongoimport --username="naomi" --authenticationDatabase="admin" --db=sample_data movies.json | ||
mongoimport --username="naomi" --authenticationDatabase="admin" --db=sample_data orders.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
storage: | ||
dbPath: m1/db | ||
net: | ||
bindIp: localhost | ||
port: 27017 | ||
security: | ||
authorization: enabled | ||
keyFile: keyfile | ||
systemLog: | ||
destination: file | ||
path: m1/mongod.log | ||
processManagement: | ||
fork: true | ||
replication: | ||
replSetName: mongodb-essentials-rs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
storage: | ||
dbPath: m2/db | ||
net: | ||
bindIp: localhost | ||
port: 27018 | ||
security: | ||
authorization: enabled | ||
keyFile: keyfile | ||
systemLog: | ||
destination: file | ||
path: m2/mongod.log | ||
processManagement: | ||
fork: true | ||
replication: | ||
replSetName: mongodb-essentials-rs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
storage: | ||
dbPath: m3/db | ||
net: | ||
bindIp: localhost | ||
port: 27019 | ||
security: | ||
authorization: enabled | ||
keyFile: keyfile | ||
systemLog: | ||
destination: file | ||
path: m3/mongod.log | ||
processManagement: | ||
fork: true | ||
replication: | ||
replSetName: mongodb-essentials-rs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
use blog | ||
show collections | ||
db.authors.insertOne({"name": "Naomi Pentrel"}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
db.authors.insertOne({"name": "Joe Nash"}) | ||
db.authors.insertMany([ | ||
{"name": "Eliot Horowitz"}, | ||
{"name": "Dwight Merriman"}, | ||
{"name": "Kevin P. Ryan"} | ||
]) | ||
db.authors.find() | ||
db.authors.find({ "name": "Naomi Pentrel"}) | ||
db.authors.find({ name: "Naomi Pentrel"}) | ||
db.authors.updateOne( | ||
{ name: "Naomi Pentrel"}, | ||
{ $set: { website: "https://naomi.codes" } } | ||
) | ||
db.authors.find({ name: "Naomi Pentrel"}) | ||
db.authors.updateMany( | ||
{ }, | ||
{ $set: { books: [] } } | ||
) | ||
db.authors.find() | ||
db.authors.deleteOne({ name: "Joe Nash" }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
db.authors.find() | ||
db.createIndex({ name: 1 }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
use lookup | ||
db.records.insert({ | ||
"name": "Naomi Pentrel", | ||
"number": "1234567890", | ||
"profession": "LinkedIn Learning Instructor", | ||
"website": "naomi.codes" | ||
}) | ||
db.records.findOne() | ||
db.records.createIndex({name: 1}) | ||
db.records.createIndex({number: 1}) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
use order_app | ||
db.oders.insertMany([ | ||
{ | ||
"time": Date(), | ||
"items": [{ | ||
"name": "Fries", | ||
"quantity": 1, | ||
"price": 2.99 | ||
},{ | ||
"name": "Diet Coke", | ||
"quantity": 1, | ||
"price": 1.99 | ||
}], | ||
"delivery_cost": 3.50, | ||
"total": 8.48, | ||
"user": { | ||
"name": "Naomi Pentrel", | ||
"address": "Sample Street 123", | ||
"email": "[email protected]", | ||
"phone": "12345678910", | ||
"balance": 10 | ||
}, | ||
"restaurant": { | ||
"name": "Burger King", | ||
"address": "Somewhere in Amsterdam" | ||
} | ||
}, | ||
{ | ||
"time": Date(), | ||
"items": [{ | ||
"name": "Fries", | ||
"quantity": 1, | ||
"price": 2.99 | ||
},{ | ||
"name": "Diet Coke", | ||
"quantity": 2, | ||
"price": 1.99 | ||
}], | ||
"delivery_cost": 3.50, | ||
"total": 10.47, | ||
"user": { | ||
"name": "Naomi Pentrel", | ||
"address": "Sample Street 123", | ||
"email": "[email protected]", | ||
"phone": "12345678910", | ||
"balance": 10 | ||
}, | ||
"restaurant": { | ||
"name": "Burger King", | ||
"address": "Somewhere in Amsterdam" | ||
} | ||
} | ||
]) | ||
db.orders.findOne() | ||
db.orders.createIndex({"user.email": 1, time: 1}) | ||
db.orders.createIndex({"restaurant.name": 1, time: 1}) | ||
db.orders.find().sort({total: -1}).limit(1) | ||
db.orders.find().sort({"restaurant.name": 1}) | ||
db.orders.find({ | ||
$expr: { | ||
$gt: [ | ||
"$total", | ||
"$user.balance" | ||
] | ||
} | ||
}) | ||
db.orders.updateMany({}, { $mul: {total: 0.9} }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
use sample_data | ||
show collections | ||
db.inventory.findOne() | ||
db.orders.findOne() | ||
db.movies.findOne() | ||
db.movies.findOne({"ratings.mndb": 10}) | ||
db.movies.findOne({"genres.0": "Musical"}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
use sample_data | ||
db.inventory.findOne() | ||
db.inventory.findOne({ "variations.quantity": { $gte: 8 } }) | ||
db.inventory.findOne({ "variations.quantity": { $gte: 17 } }) | ||
db.inventory.findOne({ "variations.quantity": { $gte: 18 } }) | ||
db.inventory.findOne({ "variations.quantity": { $gte: 22 } }) | ||
db.inventory.findOne({ "price": { $lt: 1000 } }) | ||
db.inventory.findOne({ "price": { $lt: 2000 } }) | ||
db.inventory.findOne({ "price": { $lt: 1700 } }) | ||
db.inventory.findOne({ "variations.variation": { $in: [ "Blue", "Red" ] } }) | ||
db.inventory.findOne({ "variations.variation": { $nin: [ "Blue", "Red" ] } }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
use sample_data | ||
db.inventory.findOne() | ||
db.inventory.findOne( | ||
{ | ||
$and: [ | ||
{ "variations.quantity": { $ne: 0} }, | ||
{ "variations.quantity": { $exists: true } } | ||
] | ||
} | ||
) | ||
db.inventory.findOne( | ||
{ | ||
$or: [ | ||
{ "variations.variation": "Blue" }, | ||
{ "variations.variation": "Green" } | ||
{ "variations.variation": "Teal" }, | ||
] | ||
} | ||
) | ||
db.inventory.findOne( | ||
{ | ||
$nor: [ | ||
{ price: { $gt: 8000 } }, | ||
{ "variations.variation": "Blue" } | ||
] | ||
} | ||
) | ||
db.inventory.findOne( | ||
{ | ||
$not: { price: { $gt: 20000 } }, | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
db.movies.find().sort({title: 1}) | ||
db.movies.find({}, { title: 1, genres: 1 }).sort( {title: 1}) | ||
db.movies.find({}, { title: 1, genres: 1 }).sort( {title: -1}) | ||
db.movies.find({}, { title: 1, genres: 1 }).sort( {director: 1, title: 1}) | ||
db.movies.find({}, { title: 1, genres: 1 }).sort( {title: 1}).skip(100) | ||
db.movies.find({}, { title: 1, genres: 1 }).sort( {title: 1}).skip(100).limit(5) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
use blog | ||
show collections | ||
db.authors.find() | ||
db.authors.updateOne( | ||
{ name: "Naomi Pentrel" }, | ||
{ $set: { message: "Hello World!" } } | ||
) | ||
db.authors.find() | ||
db.authors.updateMany( | ||
{}, | ||
{ $set: { message: "Hello" } } | ||
) | ||
db.authors.find() | ||
db.authors.updateMany( | ||
{}, | ||
{ $unset: { message: "" } } | ||
) | ||
db.authors.find() |
Oops, something went wrong.