//连接(就第一行末尾的这个db_name没有的话,不一定能连上,保险起见要加上)
$mongo = new \MongoClient('mongodb://{$ip}:{$port}/{$db_name}');
//选择collection方式
$collection = $mongo->{$db_name}->{$collection_name};
// 2
$db = $mongo->selectDB ( '{$db_name}' );
$collection = new \MongoCollection($db,'{$collection}');
//3
$db = $mongo->selectDB ( '{$db_name}' );
$collection = $db->selectCollection('{$collection}');
//查询
$query = ['average_star'=>'4.8'];
$cursor = $collection->find($query);
foreach ( $cursor as $item ) {
dump($item);
}
==notice==
find() returns cursor, not the array with actual data. You have to iterate the cursor.
//指定查询键名 以及用skip分页
$where = ['product_id'=>['$in'=>$product_id_import]];
$product_list = $collection->find($where,['product_id','product_name','catagory','product_attr','is_created_sku','page_url','is_sync','is_import_comment'])->limit($pagesize)->skip(($page-1)*$pagesize);
//更新
$collection->update($where,['$set'=>[‘is_sync’=>"1"]]
网友评论