|
查询操作 ' z: \, ?7 f8 ?8 b6 ]
- $filter["season_id"] = 106;- H1 M1 u3 w, ?. I* ]
- //$filter["array.8"] = 'cml123'; e8 K5 D) r/ N/ X- s
- 5 R' \ H3 z# @) d2 Z
- $filter = ["matches.events_id"=>1];* [; C1 W+ _' b4 y7 }% Z$ i
- 6 F; V- T% L$ H$ x* p4 L5 j
- $filter = ["matches.events_id"=>['$in'=>[2,3,4,5,7]]];6 ]& e( z9 }# x3 e2 p4 B
- $filter = ["matches.events_id"=>['$lt'=>'8'];
& n- P' P4 o' H* N. o - . w+ j( X1 Y& B
3 L2 k \1 S! D; i8 G3 f- 以上条件说明 http://bbs.cncml.com/forum.php?m ... &extra=page%3D14 S% [7 ]; ~% |0 I9 C
- # ?7 W5 |& @7 V4 t# y) S
- $options = [
8 }6 R: P0 [! z2 p5 B- Y - 'projection' => ['_id' => 0,"s_lastid" => 1],4 c g+ H4 e2 E; j. Z
- 'limit' => 1, //显示条数
5 J* T G3 R) M3 c) N4 p - 'skip' => 1 //跳过几条
) {( P% p. s J7 F0 O' F - ];
9 h2 p; ]- r7 X) E. L) w - 5 m1 }! {/ A: t* ~. v
- $querys = new MongoDB\Driver\Query($filter,$options);
0 s. X( V3 J' g! G; Z - $cursors = $manager->executeQuery('football.football_Competition_season_matches', $querys);
) B r8 }, _. L& {! q - $schedule= mg_querys($cursors);) G+ x3 w! S4 T4 _& M
- print_r($schedule);/ `5 L4 L, V* F3 {
复制代码 & \ e; }4 G& X+ W3 Z4 y* @9 h
/ e) S' G& A* a U. a Y
3 w: ]7 o& t3 u/ o+ H9 N
! s8 o( F& C5 K$ t8 D6 J( [, L# M------------------------------------------------------------------------------------- 一、更新前通过控制台查看数据,查看命令如下 db.sites.find().pretty() 二、通过php实现数据更新,代码如下 <?php // 1.创建数据库连接对象 $manager = new MongoDB\Driver\Manager("mongodb://localhost:27017");
) q F1 u) ?: e// 2.创建数据更新对象 $bulk = new MongoDB\Driver\BulkWrite; // 说明:更新index=2的数据,把原来的url更新为现在的内容,multi:只更新匹配到的第一条数据 $bulk->update( ['index' => 2], ['$set' => ['url' => 'https://www.java.com']], ['multi' => false, 'upsert' => false] );
0 t! }6 R7 ^& R( _// 3.创建更新操作级别对象 // 说明:MongoDB\Driver\WriteConcern::MAJORITY :抛出网络错误异常、服务器错误异常;并等待一个主服务器完成写操作 // 1000:等待超时时间 $writeConcern = new MongoDB\Driver\WriteConcern(MongoDB\Driver\WriteConcern::MAJORITY, 1000);
9 N# W2 M: V/ _2 }# M' ^' z// 4.执行写命令 // 说明:test.sites是test库下的sites集合 // $bulk:更新对象 // $writeConcern:写操作保证级别 $result = $manager->executeBulkWrite('test.sites', $bulk, $writeConcern); & @' G; H8 q8 n
// 5.输出更新后的结果 var_dump($result); 代码截图如下: 运行结果截图如下: 三、通过控制台查看更新后的数据,查看命令如下 db.sites.find().pretty() 3 F. E9 t& M& l( L4 A+ Z
$ c' v5 L" [: }( g0 R' w |