Return mongodb Collections in json_encode PHP

Asked

Viewed 71 times

1

I am assembling a REST API in PHP and I am not able to display all the returned Collections of the Mongo search, returns only one. Follow the code for those who can make a contribution I will be very grateful. =]!

private function slcTwitter($since, $until){

    // Configuration
    $dbhost = 'localhost:27017';
    $dbname = 'twitter';

    // Connect to twitter database
    $m = new Mongo("mongodb://$dbhost");
    $db = $m->$dbname;

    // Get the users collection
    $c_users = $db->twitter_lake;

    // Find
    $user = $c_users->find(array('text' => array('$all' => array(new mongoregex('/teste/i')))));

    $result = Array();
    foreach ($user as $doc) {$result = $doc;}
            return $result;
}

1 answer

0


Is it not because you are replacing one object with another?

$result = Array();
foreach ($user as $doc) {$result[] = $doc;}
        return $result;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.