当前位置:网站首页>PHP 操作mangoDb
PHP 操作mangoDb
2022-08-05 09:41:00 【不知道反正就是挺叼】
<?php
$manager = new MongoDB\Driver\Manager("mongodb://localhost:27017");
// 插入数据
$bulk = new MongoDB\Driver\BulkWrite;
$bulk->insert(['id' => 1, 'name'=>'测试', 'url' => 'csdn.com']);
$manager->executeBulkWrite('test.jihe1', $bulk);
// 查询
$filter = ['name' => '测试'];
$options = [
'projection' => ['_id' => 0],
'sort' => ['name' => -1],
];
$query = new MongoDB\Driver\Query($filter, $options);
$cursor = $manager->executeQuery('test.jihe', $query);
foreach ($cursor as $document) {
print_r($document);
}
// 编辑
$bulk = new MongoDB\Driver\BulkWrite;
$bulk->update(
['id' => 1],
['$set' => ['name' => '测试1234']],
['multi' => false, 'upsert' => false] #multi表示只更新一条数据,upsert表示如果不存在update的记录,不进行插入操作
);
$writeConcern = new MongoDB\Driver\WriteConcern(MongoDB\Driver\WriteConcern::MAJORITY, 1000);
$result = $manager->executeBulkWrite('test.jihe', $bulk, $writeConcern);
// 删除
$bulk = new MongoDB\Driver\BulkWrite;
$bulk->delete(['id' => 1], ['limit' => 1]); // limit 为 1 时,删除第一条匹配数据
$bulk->delete(['id' => 2], ['limit' => 0]); // limit 为 0 时,删除所有匹配数据
$writeConcern = new MongoDB\Driver\WriteConcern(MongoDB\Driver\WriteConcern::MAJORITY, 1000);
$result = $manager->executeBulkWrite('test.jihe', $bulk, $writeConcern);
?>边栏推荐
- Excuse me if you want to write data in mysql, with flink - connector - JDBC directly is ok, but I'm in the f
- 自定义过滤器和拦截器实现ThreadLocal线程封闭
- 15.1.1、md—md的基础语法,快速的写文本备忘录
- 【ASM】字节码操作 方法的初始化 Frame
- 2022-08-01 回顾基础二叉树以及操作
- 手把手教你纯c实现异常捕获try-catch组件
- 手写柯里化 - toString 理解
- PAT Level B - B1021 Single Digit Statistics (15)
- 阿里云存储的数据库是怎么自动加快加载速度的呢www.cxsdkt.cn怎么设置案例?
- PAT Grade B-B1020 Mooncake(25)
猜你喜欢

19.服务器端会话技术Session

19. Server-side session technology Session

C语言的高级用法

为什么我推荐使用智能化async?

What is CRM Decision Analysis Management?

express hot-reload

Analysis and practice of antjian webshell dynamic encrypted connection

The technological achievements of Shanghai Konan were selected into the "2021 Shanghai Network Security Industry Innovation Research Achievement Catalog" by the Municipal Commission of Economy and Inf

蚁剑webshell动态加密连接分析与实践

2.4G无线收发模块的应用
随机推荐
The difference between find, matches, lookingAt matching strings in matcher
Excuse me if you want to write data in mysql, with flink - connector - JDBC directly is ok, but I'm in the f
How ali cloud storage database automatically to speed up the loading speed of www.cxsdkt.cn how to set up the case?
2022.8.3
leetcode: 529. 扫雷游戏
无题八
leetcode refers to Offer 10- II. Frog jumping steps
Creo 9.0 基准特征:基准平面
The Seven Weapons of Programmers
无题二
开源一夏|OpenHarmony如何查询设备类型(eTS)
Two-table query average grouping in sql server
Marketing Suggestions | You have an August marketing calendar to check! Suggest a collection!
Neuron Newsletter 2022-07|新增非 A11 驱动、即将支持 OPC DA
leetcode points to Offer 10- I. Fibonacci sequence
express hot-reload
Seata source code analysis: initialization process of TM RM client
PAT Grade B-B1020 Mooncake(25)
IO stream articles -- based on io stream to realize folder copy (copy subfolders and files in subfolders) full of dry goods
什么是CRM决策分析管理?