mongo

//连接(就第一行末尾的这个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"]]
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容