PHP操作mongo

composer "mongodb/mongodb" : "*",

$config['mongodb'] = 'mongodb://table:[email protected]:20000,10.24.162.34:20000,10.10.162.222:20000/hyhuo',

'mongodb' => 'mongodb://192.168.56.61:27017',

$mongo_conn =  new MongoDB\Client($config['mongodb']);
        $mongo_db = $mongo_conn->hyhuo->video;
// $in 条件
 $upWhere = ['vid'=>['$in'=>[7445,7446,7447]]];
             $update = ['$set' => ['updownload_num'=>2222]];
             $ret = $mongo_db->updateMany($upWhere,$update);
 var_dump($ret);die;

$ret =  $mongo_db->find(['vid'=>['$in'=>[7445,7446,7447]]]);
foreach($ret as $row) var_dump($row);


// $set 条件
$upWhere = ['_id'=>intval($vid)];
$update = ['$set' => ['video_url_hd'=>$video_url_hd,'video_url_sd'=>$video_url_sd,'video_size' => strval($filesize)]];
$ret = $mongo_db->updateOne($upWhere,$update);


$m = new MongoClient();    // 连接到mongodb
$db = $m->test;            // 选择一个数据库
$collection = $db->runoob; // 选择集合

$cursor = $collection->find();
// 迭代显示文档标题
foreach ($cursor as $document) {
    echo $document["title"] . "\n";
}


// 移除文档
$collection->remove(array("title"=>"MongoDB 教程"), array("justOne" => true));

//查询优化
db.users.find({gender:"M"},{user_name:1,_id:0}).explain()

猜你喜欢

转载自my.oschina.net/PHPDOTAER/blog/1786302