mongo

作者: 沉睡的小精灵 | 来源:发表于2017-08-16 15:28 被阅读0次
//连接(就第一行末尾的这个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"]]

相关文章

网友评论

      本文标题:mongo

      本文链接:https://www.haomeiwen.com/subject/ydcirxtx.html