Advanced MongoDB
Advanced MongoDB
concepts
Reference: https://www.mongodb.com/docs/manual/
Data Modelling
• If an appropriate index exists for a query, MongoDB uses the index to limit the number of
documents it must scan.
• Common Query pattern
• db.collection.getIndexes()
• db.collection.createIndex()
• db.collection.dropIndex()
Aggregation in MongoDB
• Aggregation operations process multiple documents and return computed results
db.collection.aggregate([
{$stage_name: { <expression> } },
{$stage_name: { <expression> } }
])
• $cond – Evaluates a boolean expression to return one of the two specified return
expressions
Common operators used in Aggregations
• $addFields – add additional fields to documents