Episode 4 - DataGaav ka Agla Jaadu: GridFS aur Journaling

 

Episode 4  - DataGaav ka Agla Jaadu: GridFS aur Journaling

Bacche ab aur bhi curious ho gaye the. Unhone Mongo Baba se request kiya ki GridFS aur Journaling ke jaadu ke baare mein aur details mein samjhaaya jaye. Mongo Baba ne apne jaadu ka parda uthaya aur bacchon ko yeh advanced concepts ke baare mein bataya.

GridFS ka Jaadu: Bada Data Manage Karna

Mongo Baba ne GridFS ka jaadu dikhate hue kaha, "Kabhi-kabhi tumhe itni badi files ko store karna padta hai ki MongoDB ke regular documents usko handle nahi kar sakte. Aise mein hum GridFS ka jaadu use karte hain."

GridFS Kya Hai?

GridFS ek special feature hai MongoDB ka, jo tumhe large files ko store karne ki facility deta hai. Yeh un files ko chhote-chhote chunks mein tod kar alag-alag documents mein store karta hai. Har chunk default size mein 255KB ka hota hai.

  • Use Case: Agar tumhari file ka size 16MB se zyada ho, toh MongoDB us file ko directly ek document mein store nahi kar paayega. Aise mein GridFS us file ko chhote chunks mein tod kar store karta hai.

Example: Image Store Karna GridFS Mein

Imagine karo tumhe ek high-resolution image store karni hai:

  1. Tum GridFS ka use karoge image ko chunks mein todne ke liye:

    var bucket = new mongoose.mongo.GridFSBucket(db, { bucketName: 'images' }); fs.createReadStream('./big-image.jpg'). pipe(bucket.openUploadStream('big-image.jpg')). on('error', function(error) { console.log('Error:', error); }). on('finish', function() { console.log('Done!'); });

    Yeh command tumhari image ko MongoDB ke GridFS ke under chunks mein store kar degi.

  2. Retrieve Karna: Jab tumhe yeh file access karni ho, toh GridFS saare chunks ko combine karke tumhe original file wapas de deta hai.

  • Advantages: Is tarah, tumhare paas ek method hai jisse tum bahut badi files ko bhi efficiently store aur retrieve kar sakte ho, bina kisi problem ke.

Journaling ka Jaadu: Data Security aur Recovery

Bacche ab GridFS ke baare mein samajh chuke the, tab Mongo Baba ne unhe Journaling ke baare mein bataya. Journaling ek aisa process hai jo tumhare data ko safe rakhta hai aur recovery ke liye zaroori hota hai.

Journaling Kya Hai?

Journaling MongoDB ka ek mechanism hai jo har write operation ko ek journal file mein record karta hai. Agar kabhi unexpected shutdown ya crash ho jaaye, toh Journaling ki madad se tum apna data recover kar sakte ho.

  • Importance: Journaling ensure karta hai ki tumhara data crash ke baad bhi safe rahe. Agar koi operation halfway complete hota hai aur system crash ho jata hai, toh Journaling us operation ko rollback ya complete karne mein madad karta hai.

Example: Journaling in Action

  1. Write Operation: Jab tum MongoDB mein koi write operation perform karte ho:


    db.students.insertOne({ name: "Ravi", marks: 85 });

    Yeh operation pehle journal file mein record hota hai.

  2. Crash Recovery: Agar system crash ho jaaye operation ke beech mein, toh MongoDB journal file ko refer karega aur incomplete operation ko ya toh complete karega ya rollback kar dega.

  • Advantages: Is tarah se, tumhara data hamesha safe rahta hai, aur tumhe data loss ka risk nahi hota.

DataGaav ke Bacchon ki Seekh

Mongo Baba ne GridFS aur Journaling ke powerful features ko samjhaya, aur bacchon ko yeh sikhne mila ki kaise MongoDB mein bade data ko efficiently manage kiya ja sakta hai aur kaise apne data ko safe rakha ja sakta hai even in case of a system crash.

Bacche ab data storage ke advanced concepts mein mahir ho gaye the. Unhone apne data ko aur bhi securely handle karna seekh liya tha. DataGaav mein ab MongoDB ka jaadu aur bhi strong ho gaya tha.


Kahani ke is part se tumhe GridFS aur Journaling ke baare mein samajh aaya? Kya aur koi doubts ya details chahiye?

Post a Comment

0 Comments