0

From this book: https://www.oreilly.com/library/view/50-tips-and/9781449306779/ch01.html

Specifically about "Tip #7: Pre-populate anything you can".

It claims that pre-populating data is better because

MongoDB does not need to find space for them. It merely updates the values you’ve already entered, which is much faster

Is there any truth in this? I've checked the MongoDB manual about data modeling and it does not mention anything about this.

The other tips also does not cite any sources so I'm wondering if there are any basis in these tips

Edwin
  • 886
  • 2
  • 13
  • 32
  • This is also true about many other databases. If the record does not grow a lot, the update can be done in-place, which is faster. Otherwise the database has to find extra storage and move the record there. – Thilo Apr 02 '19 at 13:13

1 Answers1

1

Is there any truth in this?

Yes, if you're using MMAPv1 storage engine.

https://docs.mongodb.com/manual/core/write-performance/#document-growth-and-the-mmapv1-storage-engine

Some update operations can increase the size of the document; for instance, if an update adds a new field to the document.

For the MMAPv1 storage engine, if an update operation causes a document to exceed the currently allocated record size, MongoDB relocates the document on disk with enough contiguous space to hold the document. Updates that require relocations take longer than updates that do not, particularly if the collection has indexes. If a collection has indexes, MongoDB must update all index entries. Thus, for a collection with many indexes, the move will impact the write throughput.

Community
  • 1
  • 1
Sergio Tulentsev
  • 226,338
  • 43
  • 373
  • 367
  • Ah I see. I noticed that the book is published in 2011. Which means all the tips should apply to the MMAPv1 storage engine. I wonder if it is still true for WiredTiger though? – Edwin Apr 02 '19 at 13:17
  • @Edwin: no, this tip doesn't apply to WT. – Sergio Tulentsev Apr 02 '19 at 14:05
  • For WiredTiger, see https://stackoverflow.com/q/49596247/14955 (and, like @SergioTulentsev said, it does not do in-place-updates, so this optimization does not apply) – Thilo Apr 03 '19 at 09:12