yii2继承mongodb的模块
在使用查询的模块中:
可以使用Query模块查询
Query类似于mongo里面的db.col
$query = new Query;
$query = Yii::$app->mongodbquery;
$query->limit = 10;
$query->offset = 0;
<span style="white-space:pre"> </span>$query->select = array("name","sku");
$query->where = array("\$where"=>"this.sku=='1111'","name"=>"1111");
$query->orderBy = array("_id"=>SORT_ASC);
$query->from('catalog_product');
$product_coll = $query->all();
return $product_coll;
一定需要注意的是:在where中查询如果涉及到$where等这些字符,一定需要在前面加入\$where,反斜杠的转译字符,不然会报错的!
public function getProductCollection($from,$where=array(),$limit=10,$offset=0,$orderBy=array(),$select=array()){
$query = new Query;
//$query = Yii::$app->mongodbquery;
$query->limit = $limit;
$query->offset = $offset;
// array("_id"=>SORT_ASC)
if(!empty( $orderBy)){
$query->orderBy = $orderBy;
}
//$query->where = array("\$where"=>"this.sku=='1111'","name"=>"1111");
if(!empty( $where)){
$query->where = $where;
}
//$query->select = array("name","sku");
if(!empty( $select)){
$query->select = $select;
}
$query->from($from);
$product_coll = $query->all();
return $product_coll;
}