QA
Beginner LevelMongoDB & Mongoose

What are MongoDB Databases, Collections, and Namespaces?

❓ Interview Prompt: Explain MongoDB storage hierarchy (Instance -> Database -> Collection -> Document) and namespace naming conventions (db.collection).

MongoDB organizes data across a four-level hierarchy:

1
MongoDB Server Instance: Runs one or more mongod processes.
2
Database: Logical container holding collections and security permissions.
3
Collection: Equivalent to a SQL table; holds BSON documents.
4
Namespace: The canonical identifier formed by 'database.collection' (e.g. 'ecommerce.orders').

Code Implementation Example

typescript
import mongoose from 'mongoose';

// Select specific database in connection URI
const connectionURI = 'mongodb://localhost:27017/analytics_db';

const analyticsConn = mongoose.createConnection(connectionURI);

// Namespace: 'analytics_db.page_views'
const PageView = analyticsConn.model('page_views', new mongoose.Schema({ url: String }));
💡Connecting to specific MongoDB database namespaces using Mongoose.
🎯 Interview Key Takeaway

Namespaces are formatted as database.collection and identify specific collection storage paths in MongoDB.

#Databases#Collections#Namespaces#Beginner
Back to all MongoDB & Mongoose Questions→

More MongoDB & Mongoose Interview Questions

Beginner LevelMongoDB & Mongoose

How does the MongoDB Aggregation Pipeline work? Explain $match, $group, $lookup, and $project.

Beginner LevelMongoDB & Mongoose

What is MongoDB and how does the BSON document data model work?

Beginner LevelMongoDB & Mongoose

What is the structure of a MongoDB ObjectId and how is it generated?