Query Mongo Db and filter by associative array key
- by Failpunk
How can I search for results in Mongo DB documents using an associative array key.
Something like:
SELECT * FROM table WHERE keyword like '%searchterm%';
Here is the basic document structure
[id] => 31605
[keywords] => Array (
[keyword1] => Array (
[name] => KeyWord1
)
[keyword2] => Array (
[name] => KeyWord2
)
...
)
I would like to do a search within the keywords array on the associative array key [keyword1, keyword2].
The issue is that the name key holds the case-sensitive version of the keyword and the array key is the lower-case keyword name. I could store the lowercase keyword twice, but that seems silly.