PHP操作MongoDB

PHPDataBase;
$collection = $db->PHPCollection;


/*-----------------------------
 * 删除
 *-----------------------------
$collection->remove(array("name" => "xixi111"));
*/

/*------------------------------
 * 插入
 *------------------------------
for($i = 0;$i <= 50;$i++) {
    $data = array("name" => "xixi".$i,"email" => "673048143_".$i."@qq.com","age" => $i*1+20);
    $collection->insert($data);
}
*/

/*-------------------------------
 * 查找
 *-------------------------------
$res = $collection->find(array("age" => array('$gt' => 25,'$lt' => 40)),array("name" => true));

foreach($res as $v) {
    print_r($v);
}
*/

/*-------------------------------
 * 更新
 *-------------------------------
 $collection->update(array("age" =>22),array('$set' => array("name" => "demoxixi")));
*/
?>

 

posted @ 2020-09-22 09:15  代码是一行行敲出来的  阅读(138)  评论(0)    收藏  举报