Older driver versions allowed invalid index fields. When one of these invalid index fields exists, it gets dumped by mongodump and then upon mongorestore, the process encounters a "The field 'XXX' is not valid for an index specification" error. For example:
- Delete and re-create the index. Not a great option since dropping the index to re-create it could significantly affect performance.
- Perform the mongorestore with the "–noIndexRestore" option
- On a deployment running 3.2 or earlier, create an index with an invalid option using the mongo shell. A common invalid option previously introduced by one of the drivers was "safe".
- Upgrade it to 3.4
- Take a mongodump (any version, including 4.2.0)
- Run mongorestore (any version, including 4.2.0)
Example of creating an index with an invalid option (on deployment running 3.2.23):