Hello,
I forgot to mention this in the Post, thanks for asking.
With PHP you can represent most of data types supported by MongoDB, integers, floats numbers, strings, arrays, nested arrays and so forth, but they are some data type that can't be represented, here is the list:
php.net/manual/en/mongo.types.php
In the blog post I already used MongoCode to send javascript code to Map/Reduce.
In order to use Regex, you simple need to create a MongoRegex object:
php.net/manual/en/class.mongoregex.
...
Regular expressions follows this format "/<regex>/<flags>", and it is evaluated at the server. In my local tests, if the regexp contains an error the query returns an empty cursor, beware with this.
The equivalent request to the SQL statement username LIKE '%bar%' is this:
<?php
$filter = array(
'username' => new MongoRegex("/.*bar.*/i"),
);
$collection->find($filter);
?>
Be careful using Regex, most of the times it can't use indexes, so it will perform a data scan, therefore it is a good idea to limit the number of documents to analyze:
<?php
$filter = array(
'username' => new MongoRegex("/.*bar.*/i"),
/* I assume that 'Karma' has an index */
'karma' => array('$gt' => 10),
);
$collection->find($filter);
?>
With Regex you can do really complex queries like this:
<?php
$filter = array(
'username' => new MongoRegex("/[a-z][a-z0-9\_]+(\_[0-9])?/i"),
/* I assume that 'Karma' has an index */
'karma' => array('$gt' => 10),
);
$collection->find($filter);
?>
I hope it clarified your doubt,
Regards,