PHP 关于MongoDB的操作

<?php
header("Content-type:text/html;charset=utf-8");
$m = new MongoClient(); // 连接
$db = $m->test; // 获取名称为 "test" 的数据库
/*集合创建成功
$collection = $db->createCollection("runoob");
echo "集合创建成功";*/


/*插入
$collection = $db->runoob; // 选择集合
$document = array( 
"title" => "MongoDB", 
"description" => "database", 
"likes" => 100,
"url" => "http://www.runoob.com/mongodb/",
"by", "菜鸟教程"
);
$collection->insert($document);
echo "数据插入成功";*/

/*查询
$collection = $db->runoob; // 选择集合

$cursor = $collection->find();
// 迭代显示文档标题
foreach ($cursor as $document) {
echo $document["title"] . "\n";
}*/

/*更新
$collection = $db->runoob; // 选择集合
// 更新文档
$collection->update(array("title"=>"MongoDB"), array('$set'=>array("title"=>"MongoDB 教程")));
// 显示更新后的文档
$cursor = $collection->find();
// 循环显示文档标题
foreach ($cursor as $document) {
echo $document["title"] . "\n";
}*/

/*删除
$collection = $db->runoob; // 选择集合
$collection->remove(array("title"=>"MongoDB 教程"), array("justOne" => true));

// 显示可用文档数据
$cursor = $collection->find();
foreach ($cursor as $document) {
echo $document["title"] . "\n";
}*/

?>

 

转载于:https://www.cnblogs.com/mracale/p/5715411.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值