|
查询操作 : s: B1 X$ O$ f' ]2 q8 b3 K# o
- $filter["season_id"] = 106;
; \7 o5 V; n) {: O' d - //$filter["array.8"] = 'cml123';7 @# n$ I0 ~* B9 {/ h
, V5 N# \4 o6 M, _- S8 Y' j- $filter = ["matches.events_id"=>1];
- ?: X! d! B7 f4 l/ { - 2 D8 s( _. Z |) Z( ]
- $filter = ["matches.events_id"=>['$in'=>[2,3,4,5,7]]];
2 x6 Z7 ?% S5 `3 O - $filter = ["matches.events_id"=>['$lt'=>'8'];4 A; t; x3 h X' {" x1 m- r2 b
- " I2 B; W0 t+ Y8 d3 t6 W
- ! y1 @4 F) b9 ^2 q7 _0 C
- 以上条件说明 http://bbs.cncml.com/forum.php?m ... &extra=page%3D15 A$ I/ n& m. R+ d' q% n
+ t% j! U! A. \! q( e- $options = [
# ]# n" J' ]* X. v3 R$ O- D, u0 t9 M - 'projection' => ['_id' => 0,"s_lastid" => 1],
2 X4 A% A% z' g/ Q: F - 'limit' => 1, //显示条数; Y4 l+ i" X1 T e9 t
- 'skip' => 1 //跳过几条5 w2 O8 w5 v. ~. Q' v! ~
- ];% o( ~ O; u' ^2 ]1 k+ y$ Q$ |* n
- ! ], R! P) L( L! \& S
- $querys = new MongoDB\Driver\Query($filter,$options);1 b9 d3 M9 x0 A+ q- L. j
- $cursors = $manager->executeQuery('football.football_Competition_season_matches', $querys);" T( O; [4 U, B) @, L: S
- $schedule= mg_querys($cursors);
0 V7 f3 k2 w+ Z2 [9 {. t - print_r($schedule);! `1 J9 W, @/ a7 P) \7 B4 @" g
复制代码 0 X: z& ~8 p) K! b2 m
- u+ o2 x+ q, Q1 O
% `/ }! I; ~/ Q
/ m8 R8 z7 e! F5 t------------------------------------------------------------------------------------- 一、更新前通过控制台查看数据,查看命令如下 db.sites.find().pretty() 二、通过php实现数据更新,代码如下 <?php // 1.创建数据库连接对象 $manager = new MongoDB\Driver\Manager("mongodb://localhost:27017"); / Y: e) g* U8 D9 G
// 2.创建数据更新对象 $bulk = new MongoDB\Driver\BulkWrite; // 说明:更新index=2的数据,把原来的url更新为现在的内容,multi:只更新匹配到的第一条数据 $bulk->update( ['index' => 2], ['$set' => ['url' => 'https://www.java.com']], ['multi' => false, 'upsert' => false] ); / u4 A9 i: u X3 P, o
// 3.创建更新操作级别对象 // 说明:MongoDB\Driver\WriteConcern::MAJORITY :抛出网络错误异常、服务器错误异常;并等待一个主服务器完成写操作 // 1000:等待超时时间 $writeConcern = new MongoDB\Driver\WriteConcern(MongoDB\Driver\WriteConcern::MAJORITY, 1000); . r$ o5 e2 Y( j4 R* C
// 4.执行写命令 // 说明:test.sites是test库下的sites集合 // $bulk:更新对象 // $writeConcern:写操作保证级别 $result = $manager->executeBulkWrite('test.sites', $bulk, $writeConcern); 5 P/ m: d3 p+ n% J$ t
// 5.输出更新后的结果 var_dump($result); 代码截图如下: 运行结果截图如下: 三、通过控制台查看更新后的数据,查看命令如下 db.sites.find().pretty() ' x! c+ _# T) ^4 d+ [
7 d8 ]- y, n8 _6 r6 Q3 _3 w: K9 F4 e |