Skip to content

Instantly share code, notes, and snippets.

@brandonprry
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save brandonprry/c2de8ac2be825007c4de to your computer and use it in GitHub Desktop.
Save brandonprry/c2de8ac2be825007c4de to your computer and use it in GitHub Desktop.
<?php
$m = new MongoClient("mongodb://127.0.0.1:27017");
$m->selectDB('foo');
$collection = $m->selectCollection('test', 'phpmanual');
if ($_GET["age"] != "") {
$js = 'function(){if(this.name == "Joe"||this.age=='.$_GET["age"].')return true;}';
$cursor = $collection->find(array('$where' => $js));
foreach($cursor as $doc) {
var_dump($doc);
}
} elseif ($_GET["name"] != "") {
$js = "function(){var nom = '".$_GET["name"]."';return this.name == nom;}";
$cursor = $collection->find(array('$where' => $js));
foreach($cursor as $doc) {
var_dump($doc);
}
} elseif ($_GET["weight"] != "") {
$js = "function(){var w8 = \"".$_GET["weight"]."\";return this.weight == w8;}";
$cursor = $collection->find(array('$where' => $js));
foreach ($cursor as $doc) {
var_dump($doc);
}
} elseif ($_GET["sex"] != "") {
$js = "function(){return this.sex == \"".$_GET["sex"]."\";}";
$cursor = $collection->find(array('$where' => $js));
foreach ($cursor as $doc) {
var_dump($doc);
}
} elseif ($_GET["race"] != "") {
$js = "function(){return this.race == '".$_GET["race"]."';}";
$cursor = $collection->find(array('$where' => $js));
foreach ($cursor as $doc) {
var_dump($doc);
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment