Fix the Collection::getIndexInfo method for missing "unique" option #117
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I saw this issue when dealing with a bug in Doctrine ODM. They have a command handling indexes changes.
In that command, they check that the defined mapping is the same as the indexes returned by mongodb (code here for the curious). If not, unknown indexes are removed, and then "ensureIndexes" is called.
I got a very bad situation in production where some of my indices were removed, and re-created, which was taking a very long time and basically broke everything (and was doing so in total absence of error exit).
What is wrong
The
isMongoIndexEquivalentToDocumentIndex
from Doctrine was not returning true when comparing some of my indexes.That's because the response from the old Mongo extension and what mongo-php-adapter returns is not always the same, especially when there is the
unique
option set on the index.The fix
Adding back the
unique
key in the array was enough to fix the bug in the schema update command, but I took a look inside the old Mongo extension and server code and it looks like that the option is only returned if it's true (code here), so I added a smallif
to mimic this behavior too.Thanks 🍻