sql >> Base de Datos >  >> NoSQL >> MongoDB

¿Cómo creo un feed JSON a partir de una colección de MongoDB?

    $cursor = $this->collection->find($params);
    $return = array();
    $i=0;
    while( $cursor->hasNext() )
    {

        $return[$i] = $cursor->getNext();
        // key() function returns the records '_id'
        $return[$i++]['_id'] = $cursor->key();
    }
    return json_encode($return);

Así es como devuelvo JSON de Mongo.