Skip to content

Instantly share code, notes, and snippets.

@kidsil
Created June 29, 2010 06:47
Show Gist options
  • Save kidsil/456879 to your computer and use it in GitHub Desktop.
Save kidsil/456879 to your computer and use it in GitHub Desktop.
So, you want to search in your MongoDB?
Here's how to do so
'puki' is my collection, for normal people it would be articles, pages or whatever
$query is what I'm searching for, here I have inside puki a body and name,
I want to retrieve pukis that have $query in their name or body
$db = MangoDB::instance();
$puki = $db->find('puki', array(
new MongoCode("function() { return (/$query/i.test(this.body) || (/$query/i.test(this.name))}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment