[MongoDB] mongodb与php
时间:2021-07-01 10:21:17
帮助过:2人阅读
// 连接到mongodb
$mongoClient =
new MongoClient();
// 选择一个数据库
$db =
$mongoClient->
test;
//获取集合
$collection=
$db->
users;
//更新文档
$condition=
array();
$condition["id"]=1
;
$data=
array();
$data[‘name‘]="wangwu"
;
$data[‘age‘]="11"
;
$collection->update(
$condition,
$data);
//插入文档
$data=
array();
$data[‘id‘]=4
;
$data[‘name‘]="哈哈"
;
$data[‘age‘]="11"
;
$collection->insert(
$data);
//删除文档
$condition=
array();
$condition[‘id‘]=2
;
$collection->remove(
$condition);
//查询文档
$users=
$collection->
find();
foreach (
$users as $k =>
$v) {
print_r(
$v);
}
?>
[MongoDB] mongodb与php
标签: