Question

I have a couple of fields in my documents that I want to make sure they are unique across a collection if they store non-null values, but I will never need to query for them - e.g. md5 hash of a file. As far as I've checked in the MongoDB documentation, for this situation it is suggested to use a unique and sparse index. My question is: is there any way to avoid creating an index, given the fact that I will never query on the md5 field of any document?

No correct solution

OTHER TIPS

Since you will not be querying for these fields it is very difficult to say.

You could use query magic but then you might not have the values available to you, otherwise your only option is to enforce this client side which could create race conditions.

There's no way to guarantee uniqueness without creating indexes, as MongoDB doesn't provide any mechanism to enforce constraints.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top