Set up MongoDB (local install or Atlas free tier). Atlas gives you a cloud database in minutes — no installation needed.
const { MongoClient } = require('mongodb');
const client = new MongoClient(
'mongodb://localhost:27017'
);
async function connectDB() {
await client.connect();
console.log('Connected to MongoDB');
return client.db('pixelcraft');
}
// GET all images
app.get('/api/images', async (req, res) => {
const db = await connectDB();
const images = await db.collection('images')
.find().toArray();
res.json(images);
});
// POST new image
app.post('/api/images', async (req, res) => {
const db = await connectDB();
const image = {
...req.body,
createdAt: new Date(),
};
const result = await db.collection('images')
.insertOne(image);
res.status(201).json({
...image, _id: result.insertedId
});
});
Add images via API → restart server → images are still there! This is the whole point. Data persists independently of the application.
Open MongoDB Compass. Connect to your database. See the pixelcraft database, the images collection, the documents you created. Run queries visually.
git switch -c feature/PIXELCRAFT-045-mongodb
git add server/ package.json
git commit -m "Integrate MongoDB for persistent storage (PIXELCRAFT-045)"
git push origin feature/PIXELCRAFT-045-mongodb
# PR → Review → Merge → Close ticket ✅
Database fundamentals.
CRUD + guarantees. ACID has defined database engineering for decades.