Perform case-insensitive lookup on an Array in MongoDB?

Posted by Hal on Stack Overflow See other posts from Stack Overflow or by Hal
Published on 2010-05-21T07:30:54Z Indexed on 2010/05/22 18:10 UTC
Read the original article Hit count: 486

Filed under:
|
|
|
|

So, I've decided to get my feet wet with MongoDB and love it so far. It seems very fast and flexible which is great. But, I'm still going through the initial learning curve and as such, I'm spending hours digging for info on the most basic things.

I've search throughout the MongoDB online documentation and have spent hours Googling through pages without any mention of this. I know Mongo is still quite new (v1.x) so it explains why there isn't much information yet. I've even trying looking for books on Mongo without much luck. So yes, I've tried to RTFM with no luck, so, now I turn to you.

I have an Array of various Hashtags nested in each document (ie: #apples, #oranges, #Apples, #APPLES) and I would like to perform a case-insensitive find() to access all the documents containing apples in any case. It seems that find does support some regex with /i, but I can't seem to get this working either.

Anyway, I hope this is a quick answer for someone.

Here's my existing call in PHP which is case sensitive:

$cursor = $collection->find(array( "hashtags" => array("#".$keyword)))->sort(array('$natural' => -1))->limit(10);

Help?

© Stack Overflow or respective owner

Related posts about php

Related posts about find