'Two-way key index with MongoDB?
I was wondering if it was possible to have a two-way key index in a MongoDB instance. Say, if there was a pair "foo":"bar", I would be able to efficiently access the pair by querying for either foo or bar (and it would return either the pair or the other key). Is this possible? If not, what is the best way I can go about doing this?
I have tried looking for something like this on the MongoDB documentation for indexes but could not find anything.
Solution 1:[1]
If your key is expected to have different values , better you just create different keys assigning your original key/value pair as values as follow:
key1:"foo"
key2:"bar"
and create index on both key1 and key2 ..
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | R2D2 |
