Databases : understand how to organize and to use data

NoSQL Document-Oriented Databases : Project DB implementation with MongoDB

How to organize data? remember:

quiz manager app

What becomes a dedicated collection? What becomes nested document?

Possible solution for the exercise

How to perform "joins" across collections? 1st, store the reference

Note: reference can be made by whatever field, not necessarily by the id fields

How to perform "joins" across collections? 2nd: use $lookup

Starting implementation


Basic operations for questions : create


//create
db.questions.insertOne({
    choices:[
        {
            choice:1,
            choiceLabel:"abc",
            valid:true
        }
    ],
    difficulty: 0,
    subject:"",
    topics:[]
});

Basic operations for questions : delete


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

Note: you can put whatever criteria you want instead of id, be sure then to target only the documents you really want to delete, that's quite dangerous

Basic operations for questions : update


//updateById
db.questions.updateOne(
    {_id:ObjectId('')},
    {$set: {subject:''}}
)

Note: you can put whatever criteria you want instead of id, be sure then to target only the documents you really want to update

Basic operations for questions : find


//search by topics
db.questions.find({
    topics: ['']
})