You have a MongoDB collection that receives thousands of writes per second. Which schema design approach helps reduce write conflicts and improves write performance?
Think about how MongoDB locks documents during writes and how document size affects write speed.
Small, flat documents reduce the chance of write conflicts and improve write throughput because MongoDB locks at the document level. Embedding large arrays or storing all data in one document can cause large document sizes and slow writes.
Consider a MongoDB collection where user profiles embed an array of login timestamps. You run this update:
db.users.updateOne({ _id: 1 }, { $push: { logins: ISODate() } })What is the expected effect on write performance if the logins array grows very large?
Consider how MongoDB handles document updates and the impact of large arrays on document size.
MongoDB rewrites the entire document on update. Large arrays increase document size, causing slower writes and more disk I/O.
Which MongoDB schema design below best supports a write-heavy workload where each write is a new event that must be stored quickly?
Think about how document size and indexing affect write speed and storage.
Storing each event as a separate small document allows fast inserts and avoids large document rewrites. Indexing on timestamp supports efficient queries.
A MongoDB collection stores user activity logs embedded inside user documents as arrays. Over time, writes slow down significantly. What is the most likely cause?
Consider how MongoDB handles document updates and the impact of large embedded arrays.
Large arrays cause the entire document to be rewritten on each update, slowing down writes as document size grows.
You have a MongoDB cluster with sharding enabled to handle a write-heavy workload. Which shard key choice best supports even write distribution and avoids write hotspots?
Think about how shard keys affect data distribution and write load balancing.
A compound shard key with a random suffix spreads writes across shards evenly, avoiding hotspots caused by monotonically increasing keys.