mongodb php远程连接

i have a script that work with Mongodb There is the code

  <?php
if(isset($_SESSION["steamid"])) {
include_once('steamauth/userInfo.php');
    $connection = new MongoClient();
    $collection = $connection->selectDB('admin')->selectCollection('site_users');
    $list = $collection->find();
    $steam_list = array();
    foreach($list as $key => $value){
        $steam_list[] = $value['steamid'];
    }

    if(!in_array($_SESSION['steamid'],$steam_list)){
        $collection->save(array('steamid' => $_SESSION['steamid'],'name' => $_SESSION['steam_personaname'],'ip' => $_SERVER['REMOTE_ADDR']));
    }

?>

thats mean when user is logged in with his steam account connect to Mongodb first question here the code try to connect to local Mongodb Server If yes i want to transform this connection into a remote connexion so ican use MongolabDb Hosting with it , waiting you helps guys thanks :)

MongoCollection::find method return MongoCursor.

Need convert result. iterator_to_array

<?php
if(isset($_SESSION["steamid"])) {
    include_once('steamauth/userInfo.php');
    $connection = new MongoClient();
    $collection = $connection->selectDB('admin')->selectCollection('site_users');
    $cursor = $collection->find();
    $list=iterator_to_array($cursor)
    $steam_list = array();
    foreach($list as $key => $value){
        $steam_list[] = $value['steamid'];
    }

    if(!in_array($_SESSION['steamid'],$steam_list)){
        $collection->save(array('steamid' => $_SESSION['steamid'],'name' => $_SESSION['steam_personaname'],'ip' => $_SERVER['REMOTE_ADDR']));
    }

?>