//添加
$mongo = Yii::app()->study->getDbInstance();
for($i=1;$i<100;$i++)
{
$_id = rand(10,10000);
$age = rand(5, 50);
$insertData = array('_id'=>$_id,'name'=>'李jie'.$_id,'age'=>$age,'content'=>$age.'奥法'.$_id);
$mongo->study1->insert($insertData);
}
//查询
$mongo = Yii::app()->study->getDbInstance();
$result = $mongo->study1->find(array('_id'=>array('$gt'=>10)),array('_id','name'));
foreach ($result as $key=>$val){
echo "<pre>";
print_r($val);
}
$operators = array(
'greater' => '$gt',
'>' => '$gt',
'greatereq' => '$gte',
'>=' => '$gte',
'less' => '$lt',
'<' => '$lt',
'lesseq' => '$lte',
'<=' => '$lte',
'noteq' => '$ne',
'!=' => '$ne',
'<>' => '$ne',
'in' => '$in',
'notin' => '$nin',
'all' => '$all',
'size' => '$size',
'type' => '$type',
'exists' => '$exists',
'notexists' => '$exists',
'elemmatch' => '$elemMatch',
'mod' => '$mod',
'%' => '$mod',
'equals' => '$$eq',
'eq' => '$$eq',
'==' => '$$eq',
'where' => '$where'
);
//修改
$mongo = Yii::app()->study->getDbInstance();
//public function update (array $criteria, array $new_object, array $options = null)
$mongo->study1->update(array('_id'=>1231),array('name'=>'lijie'));
//删除
$mongo = Yii::app()->study->getDbInstance();
//public function remove (array $criteria = null, array $options = null)
$mongo->study1->remove(array('_id'=>1231));