What is MongoDB aggregation?
Aggregation processes data through a pipeline of stages: $match (filter), $group (group and aggregate like sum/avg), $sort, $limit, $skip, $lookup (join collections), $unwind (deconstruct arrays), $project (select fields). Used for analytics and complex data processing.
Verify This Answer
Cross-check this information using these trusted sources:
More FAQs in Node.js MongoDB and Mongoose Interview Questions Schemas, Indexes, and Aggregation
MongoDB is a NoSQL database that stores JSON-like documents. Mongoose is an ODM (Object Data Modeling) library for MongoDB in Node.js that adds schema definition, validation, type casting, middleware hooks, population (ref), and query building.
Indexes create a sorted data structure that speeds up queries. Without indexes, MongoDB scans every document (collection scan). With indexes, MongoDB uses the index (index scan). Types: single field, compound (multiple fields), unique (no duplicates), and text (for search).
ref is a schema option that references documents in another collection (stores ObjectId). populate replaces the ObjectId with the actual document when querying: Post.find().populate('author', 'name email'). This is like a JOIN in SQL.
Still have questions?
Browse all our FAQs or reach out to our support team
