C100DBA · Question #120
Addding the index {a:l} can potentially decrease the speed of which of the following operations? Check all that apply.
Options A and C are correct - both are write operations that force MongoDB to maintain the {a:1} index, adding overhead with every write. A is correct because even though the query filter targets field b, the update modifies field a via $inc. Since a is indexed, MongoDB must…
Question
Addding the index {a:l} can potentially decrease the speed of which of the following operations? Check all that apply.
Options
- Adb.collection.update({b:456>, {$inc: {a:l> })
- Bdb.collection.find( {a : 232} )
- Cdb.collection.insert( { a:341})
Explanation
Options A and C are correct - both are write operations that force MongoDB to maintain the {a:1} index, adding overhead with every write.
A is correct because even though the query filter targets field b, the update modifies field a via $inc. Since a is indexed, MongoDB must update the index entry after each modification - making writes slower than without the index.
C is correct because every insert that contains field a requires a new entry to be written into the index. More indexes always mean more work per insert.
B is wrong - a find querying on a is exactly the operation this index is designed to accelerate. The index makes reads on a faster, not slower.
Memory tip: Indexes are a read/write trade-off - they speed up queries (find) but add overhead to any write (insert, update, delete) that touches the indexed field. Ask yourself: "Does this operation write to the indexed field?" If yes, the index can slow it down.
Topics
Community Discussion
No community discussion yet for this question.