Query Mongo Db and filter by associative array key
Posted
by
Failpunk
on Stack Overflow
See other posts from Stack Overflow
or by Failpunk
Published on 2010-12-24T00:20:55Z
Indexed on
2010/12/24
0:54 UTC
Read the original article
Hit count: 164
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.
© Stack Overflow or respective owner