mongodb php远程连接


mongodb php remote connexion

我有一个可以使用Mongodb的脚本

  <?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']));
    }
?>

这意味着当用户使用他的steam帐户登录时,连接到Mongodb这里的第一个问题是,代码尝试连接到本地Mongodb服务器如果是的,我想将此连接转换为远程连接,所以我可以使用MongolabDb主机,等待您的帮助,谢谢:)

MongoCollection::find方法返回MongoCursor。

需要转换结果。迭代器_数组

<?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']));
    }
?>