|
查询操作 9 V9 J. g% j0 S4 h% o, ?5 R. J
- $filter["season_id"] = 106;
5 ~! D9 y$ ?, n - //$filter["array.8"] = 'cml123';
: i- l& G1 E1 s# i& T
, a1 r3 a y9 ]: X( ]4 L, e- $filter = ["matches.events_id"=>1];! N. U# p1 r2 N% T; r9 [8 B0 ~
: ^& N9 t, O4 ~( H- R) ^: o- $filter = ["matches.events_id"=>['$in'=>[2,3,4,5,7]]];
6 {. I) a @1 y& u# n- r, @! e - $filter = ["matches.events_id"=>['$lt'=>'8']; M" D: Y0 V- {& Z- X) C
9 a/ G% d2 ^5 |3 n- ( M4 g0 K1 P2 S3 i$ ~
- 以上条件说明 http://bbs.cncml.com/forum.php?m ... &extra=page%3D1
( D/ ?! L( a. Y' M) G
2 l( R8 L* ]! f5 X- $options = [$ ?! |) A. b/ H) }$ E
- 'projection' => ['_id' => 0,"s_lastid" => 1],
/ A; c# [; {- a1 G( S0 Z - 'limit' => 1, //显示条数
: o Y- ]+ E$ C1 ~ - 'skip' => 1 //跳过几条) [1 k8 x3 T/ K
- ];
9 `" f6 Y6 ^* A! p5 b5 v - , \6 B! Y0 H" t/ {7 m
- $querys = new MongoDB\Driver\Query($filter,$options);
+ ]" D. y! j- ~* Z& b, C' p- R0 { - $cursors = $manager->executeQuery('football.football_Competition_season_matches', $querys);; r' e9 i. ]$ `% m$ T
- $schedule= mg_querys($cursors);
5 [, J$ Q: B1 K/ [ - print_r($schedule);! o/ I% Y$ z. z$ t' m( d$ p" }/ h, u; D
复制代码
. T- h! [) I6 R6 U2 Q! l" F 2 j: j: [+ w c% N |
# V, [7 K3 t& T5 }, K5 p7 }0 |- ~( I! Q
------------------------------------------------------------------------------------- 一、更新前通过控制台查看数据,查看命令如下 db.sites.find().pretty() 二、通过php实现数据更新,代码如下 <?php // 1.创建数据库连接对象 $manager = new MongoDB\Driver\Manager("mongodb://localhost:27017");
4 _) p; {. R5 u& T// 2.创建数据更新对象 $bulk = new MongoDB\Driver\BulkWrite; // 说明:更新index=2的数据,把原来的url更新为现在的内容,multi:只更新匹配到的第一条数据 $bulk->update( ['index' => 2], ['$set' => ['url' => 'https://www.java.com']], ['multi' => false, 'upsert' => false] );
7 M1 W- s! @& q) }9 a* d// 3.创建更新操作级别对象 // 说明:MongoDB\Driver\WriteConcern::MAJORITY :抛出网络错误异常、服务器错误异常;并等待一个主服务器完成写操作 // 1000:等待超时时间 $writeConcern = new MongoDB\Driver\WriteConcern(MongoDB\Driver\WriteConcern::MAJORITY, 1000);
* A! b0 }' i2 ^// 4.执行写命令 // 说明:test.sites是test库下的sites集合 // $bulk:更新对象 // $writeConcern:写操作保证级别 $result = $manager->executeBulkWrite('test.sites', $bulk, $writeConcern);
& w4 [( G# Z( r9 h// 5.输出更新后的结果 var_dump($result); 代码截图如下: 运行结果截图如下: 三、通过控制台查看更新后的数据,查看命令如下 db.sites.find().pretty()
; U+ g$ Q; R% c8 X' R! f4 N, z* u6 s: E e
|