Return mongodb collections in json_encode PHP

1

I am mounting a REST API in PHP and I am not able to display all the collections returned from the mongo search, returns only one. Follow the code for anyone who can make a contribution I'll 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;
}
    
asked by anonymous 22.07.2016 / 16:03

1 answer

0

Is not it because you're replacing one object with another?

$result = Array();
foreach ($user as $doc) {$result[] = $doc;}
        return $result;
    
22.07.2016 / 17:26