views:

671

answers:

1

Example:

> db.stuff.save({"foo":"bar"});

> db.stuff.find({"foo":"bar"}).count();
1
> db.stuff.find({"foo":"BAR"}).count();
0
+6  A: 

You could use a regex.

In your example that would be:

db.stuff.find( { foo: /bar/i } );

I must say, though, maybe you could just downcase (or upcase) the value on the way in rather than incuring the extra cost everytime you find it. Obviously this wont work for people's names and such, but maybe use-cases like tags.

thenduks
This works perfectly. Got it working in PHP with: $collection->find(array('key' => new MongoRegex('/'.$val.'/i')));
Luke Dennis