Skip to content

Instantly share code, notes, and snippets.

@darkredz
Created July 20, 2012 18:02
Show Gist options
  • Select an option

  • Save darkredz/3152294 to your computer and use it in GitHub Desktop.

Select an option

Save darkredz/3152294 to your computer and use it in GitHub Desktop.
Using MongoRegex vs Javascript Expression $where
<?php
//With proper Indexing this will be a lot faster than JS Expression
$categoryInput = strtolower($postedFromSomeWhere);
$categoryInput = preg_quote($categoryInput);
$regex = new MongoRegex ('/^'. $categoryInput .'$/i');
$categoryModel = new Category;
$rs = $categoryModel->findOne(
'username' => 'leng',
'category' => $regex,
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment