查询操作 % K) m4 F- D2 Q+ u, s" M n
- $filter["season_id"] = 106;
z. Q$ K5 p" y - //$filter["array.8"] = 'cml123';( Z+ Q6 m3 c) u1 g
- 4 ?! O; V; B% T8 E% b
- $filter = ["matches.events_id"=>1];
: z' `9 x5 {5 ]% P8 V, S; q) N) y" i - . M1 J) a1 ?2 _+ d I
- $filter = ["matches.events_id"=>['$in'=>[2,3,4,5,7]]];5 ^. b9 m A" P0 {- V' p- y
- $filter = ["matches.events_id"=>['$lt'=>'8'];
4 y# k# t Q% i" A+ C' ] - * H! k) o& F/ a2 r
, }. s! s$ x2 w! O- 以上条件说明 http://bbs.cncml.com/forum.php?m ... &extra=page%3D1
2 G3 L/ [, B2 q# b" s9 ? - + X, E+ ?$ [, C, T! h) b
- $options = [5 E) Y4 k o. J
- 'projection' => ['_id' => 0,"s_lastid" => 1],
4 X; ?% q* h+ g V$ R: N - 'limit' => 1, //显示条数
3 C! a0 D$ x, b; I& N, l - 'skip' => 1 //跳过几条) _$ F# @/ R' m: }0 \+ j% A
- ];7 m Q1 ?7 I2 Y5 k# }
- , F" t' D: s& E- l
- $querys = new MongoDB\Driver\Query($filter,$options);9 R0 C1 c9 O4 q5 X- R/ b" j0 Y
- $cursors = $manager->executeQuery('football.football_Competition_season_matches', $querys);1 W0 B$ N0 F* s( `: k
- $schedule= mg_querys($cursors);
) p% c; o' I; W! t* P - print_r($schedule);1 ?, K1 `- g6 `4 X/ k1 Z
复制代码
+ P$ c t. F! Y& f) \8 b
/ _+ I4 C' q) }6 u
& @0 C/ a$ a2 R7 n% I, c! Z% Z5 v% k7 G) P6 Y+ I
------------------------------------------------------------------------------------- 一、更新前通过控制台查看数据,查看命令如下 db.sites.find().pretty() 二、通过php实现数据更新,代码如下 <?php // 1.创建数据库连接对象 $manager = new MongoDB\Driver\Manager("mongodb://localhost:27017"); 7 x( u% o% }7 y# 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] ); , L8 c# G3 b& c. ?3 P( f! y
// 3.创建更新操作级别对象 // 说明:MongoDB\Driver\WriteConcern::MAJORITY :抛出网络错误异常、服务器错误异常;并等待一个主服务器完成写操作 // 1000:等待超时时间 $writeConcern = new MongoDB\Driver\WriteConcern(MongoDB\Driver\WriteConcern::MAJORITY, 1000);
! |9 p% _; Y. @" {1 o3 y& M// 4.执行写命令 // 说明:test.sites是test库下的sites集合 // $bulk:更新对象 // $writeConcern:写操作保证级别 $result = $manager->executeBulkWrite('test.sites', $bulk, $writeConcern); , k4 t, W, t) O4 j, D: @
// 5.输出更新后的结果 var_dump($result); 代码截图如下: 运行结果截图如下: 三、通过控制台查看更新后的数据,查看命令如下 db.sites.find().pretty() - K- L1 {6 G: ~, T- f
) ?; i8 _6 m6 Q8 n* ] |