Home > Enterprise >  Does a unique index in background mode ever allow a duplicate record from being written?
Does a unique index in background mode ever allow a duplicate record from being written?

Time:10-04

Does indexing in background mode something that only affects index creation or also indexing during runtime when records are written. I just hope that it doesn't mean that a record is written to DB first then the indexing is done in the background as for unique indexes that would possibly allow duplicate data? Just want to ensure my understanding is correct as I cannot tell for sure in the docs

CodePudding user response:

Background versus foreground index creation just describes how the index is initially created. All indexes are updated synchronously upon writes from the client after creation. In your situation the database would indeed reject duplicate entries from being inserted (or updated) once the unique index has been built (or fail to build if duplicate data exists in the collection when you attempt to build the index).

Also worth mentioning that concepts of foreground and background index builds have gone away as of 4.2 (referenced here).

  • Related