Skip to content

Commit

Permalink
Add remaining script files
Browse files Browse the repository at this point in the history
  • Loading branch information
npentrel committed Mar 21, 2022
1 parent 7247bb1 commit c8f2aec
Show file tree
Hide file tree
Showing 38 changed files with 509 additions and 22 deletions.
3 changes: 1 addition & 2 deletions 1/1_2.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

npm version
npm install -g m
m latest
Expand All @@ -7,4 +6,4 @@ brew tap mongodb/brew
brew install mongosh
mongosh --version
brew install mongodb-database-tools
mongoimport
mongoimport
4 changes: 1 addition & 3 deletions 1/1_3.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@ npm version
sudo npm install -g m
m latest
mongod --version
docs.mongodb.com/mongodb-shell/install/

sudo apt-get install mongodb-database-tools
sudo apt-get install mongodb-database-tools
4 changes: 1 addition & 3 deletions 1/1_4.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@ npm version
sudo npm install -g m
m latest
mongod --version
docs.mongodb.com/mongodb-shell/install/

sudo apt-get install mongodb-database-tools
sudo apt-get install mongodb-database-tools
7 changes: 0 additions & 7 deletions 1/2_1.sh

This file was deleted.

7 changes: 0 additions & 7 deletions 1/2_3.sh

This file was deleted.

7 changes: 7 additions & 0 deletions 2/2_1.sh
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"})
18 changes: 18 additions & 0 deletions 2/2_3.sh
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
28 changes: 28 additions & 0 deletions 2/2_4.sh
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']
4 changes: 4 additions & 0 deletions 2/2_5.sh
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
15 changes: 15 additions & 0 deletions 2/m1.conf
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
15 changes: 15 additions & 0 deletions 2/m2.conf
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
15 changes: 15 additions & 0 deletions 2/m3.conf
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
3 changes: 3 additions & 0 deletions 3/3_2.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
use blog
show collections
db.authors.insertOne({"name": "Naomi Pentrel"})
20 changes: 20 additions & 0 deletions 3/3_3.sh
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" })
2 changes: 2 additions & 0 deletions 3/3_4.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
db.authors.find()
db.createIndex({ name: 1 })
10 changes: 10 additions & 0 deletions 3/3_6.sh
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 removed 3/script.sh
Empty file.
67 changes: 67 additions & 0 deletions 4/4_11.sh
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} })
7 changes: 7 additions & 0 deletions 4/4_2.sh
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"})
11 changes: 11 additions & 0 deletions 4/4_3.sh
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" ] } })
32 changes: 32 additions & 0 deletions 4/4_4.sh
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 } },
}
)
6 changes: 6 additions & 0 deletions 4/4_5.sh
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)
18 changes: 18 additions & 0 deletions 4/4_6.sh
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()
Loading

0 comments on commit c8f2aec

Please sign in to comment.