There is a divergence of the validation path for _id fields between inserts & updates. We should refactor these two paths (and any additional create/update validation paths, if they exist) to rely on the same validation logic for consistency and increased test coverage.
The validation is defined:
- insert: insert.cpp
- update: storage_validation.cpp
Background
Originally, we were using storageValidEmbedded method in updates. The call stack was like:
- storage_validation::scanDocument
- → storage_validation::storageValidIdField
- → BSONObj::storageValidEmbedded.
Later in SERVER-75517, we moved away from using the storageValidEmbedded method as it is not compatible for use with ConstElements, as described in the ticket. We have duplicate validation logic between storage and inserts.
Due to this divergence, we had the issues SERVER-75879 and SERVER-75880 where we permitted upserting an invalid document which is not by an insert.
- is related to
-
SERVER-75517 illegal format of `_id` possible via upsert
- Closed
-
SERVER-75880 Upsert permits _id values containing $-prefixed paths which cannot be inserted using insert command
- Closed