PHP操作MongoDB

<?php
error_reporting(7);

$conn = new Mongo();

$db = $conn->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")));
*/
?>

你可能感兴趣的:(mongodb)