Skip to the content.

Learning NoSQL / MongoDB with zhashkevych

NoSQL with MongoDB Video

Introductory

MongoDB University - MongoDB Basics

MongoDB University - MongoDB for SQL Pros

MongoDB University - Authentication & Authorization

Intermediate

MongoDB University - MongoDB Performance

MongoDB University - MongoDB for Python Developers

Advanced

MongoDB University - Data Modeling

Steps

Create Docker cCntainer with Mongo

docker run --name mongo_test --rm -d -e MONGO_DATABASE=admin -e MONGO_INITDB_ROOT_USERNAME=root -e MONGO_INITDB_ROOT_PASSWORD=qwerty -p 27019:27017 mongo

Go to Mongo Container

docker exec -it <hash> /bin/bash

Go to Mongo

mongo -u root -p qwerty --authenticationDatabse admin

Show all dbs

show dbs;

Switch to admin db

use admin;

Switch to test_db

use test_db;

Create new document in memberships-collection in test_db

db.memberships.insertOne({
    title: "Basic 3 month",
    price: 1999,
    duration: 3
})

Get all documents from memberships collection

db.memberships.find({})

Get all documents with indents

db.memberships.find({}).pretty()

Get with filter - duration = 3

db.memberships.find({
    duration: 3
}).pretty()

Get with filter - duration >= 6

db.memberships.find({
    duration: {$gte: 6}
}).pretty()

Get with filter - duration >= 3

db.memberships.find({
    duration: {$gte: 3}
}).pretty()

Insert documents with price-object

db.memberships.insertOne({
    title: "Basic 6 month",
    duration: 6,
    price: {
        value: 3999,
        currency: "UAH"
    }
})
db.memberships.find({})

db.memberships.insertOne({
    title: "Basic 6 month",
    duration: 6,
    price: {
        value: 3999,
        currency: "UAH"
        bonuses: ['SPA', 'Massage']
    }
})

db.memberships.find({}).pretty()

Insert document with one parameter

db.memberships.insertOne({
    name: "Jack"
})

db.memberships.find({}).pretty()

Than we can use MongoDB Compass with autocompletion

Update bonuses in document with ObjectId

db.memberships.updateOne({
    _id: ObjectId('...')
},
{
    $addToSet: {
        bonuses: "SPA"
        }
});

Update with adding new bonus in document with ObjectId

db.memberships.updateOne({
    _id: ObjectId('...')
},
{
    $push: {
        bonuses: "SPA"
        }
});

Delte document with ObjectId

db.memberships.deleteOne({
    _id: ObjectId('...')
});