Click here to Skip to main content
15,887,585 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am working on a regex search box which will return only document titles from my document collection.

It may seem a simple task, however, as I am a beginner, I am struggling on completing this task.

This is my code:

XML
<?php
//error_reporting(0);
    require 'view/header.php';
    include 'config.php';
?>

<form action="" method="post">
    <h4>Insert a regex command below</h4>
    <!--Regex: <input type="text" name="regex"/>-->
    Title: <input type="text" name="title"/>
    <input type="submit" value="Search"/><br/><br/>
</form>

<?php
    $m = new MongoClient();
    $db = $m->selectDB("fldev");
    $collections = $db->getCollectionNames();
    $collection = $m->selectCollection('fldev', 'docs');
    //var_dump($collection);

    echo "<pre>";
    foreach ($collections as $collectionName) {
      echo "Found collection: ", $collectionName, "<br/>";
    }
    echo "</pre><br/>";
?>

<?php
    //$regex=(isset($_POST["regex"]) ? $_POST["regex"] : "");
    $title=(isset($_POST["title"]) ? $_POST["title"] : "");
    //var_dump($regex);

    //$results = $collection->findOne(array('title' => 'greeklish abstract'));

  echo "<pre>";
    var_dump($collection->findOne(array('$title' => 'greeklish abstract')));
    var_dump($collection->findOne(array('$id' => '526937f8fa96470e3944a7ef')));
  echo "</pre>";
?>

<?php
    require 'view/footer.php';
?>



I tried to just get one document from the collection however it outputs 'NULL' as in there is no document found.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900