|
查询操作 & Q" x$ B, C3 |2 x. j# R; m
- $filter["season_id"] = 106;1 T. q6 }! u! Y2 Q/ c
- //$filter["array.8"] = 'cml123';
" S* n. ]4 }+ ?- [2 Z
# G+ t; E: p, H7 B- $filter = ["matches.events_id"=>1];
6 T4 H; q5 I2 h* I7 W
/ p$ u4 z& L7 J$ S3 v- $filter = ["matches.events_id"=>['$in'=>[2,3,4,5,7]]];
; ^9 b" p8 f. g: P( o! Z - $filter = ["matches.events_id"=>['$lt'=>'8'];
: T" K1 t @, ` - ) O6 s: y4 j& `$ j& e1 ^: K7 \
- a2 ?- q1 f- F# Z0 `
- 以上条件说明 http://bbs.cncml.com/forum.php?m ... &extra=page%3D1' _/ v) y6 W, E3 a' t" p- h
, t. D" j- s9 Z, }- $options = [
1 e" @1 B' i+ o4 j9 q4 d$ ^6 R& M - 'projection' => ['_id' => 0,"s_lastid" => 1],) [8 p6 M( @6 e+ F
- 'limit' => 1, //显示条数
* k Z* i* ?: K9 Z: f" |; { - 'skip' => 1 //跳过几条! |. s* q7 {+ H0 i( O9 |3 Q( C/ O
- ];
$ f* E. C8 M3 }; v. m- J, l - 2 R* z" E& c1 C6 _ e' P: y
- $querys = new MongoDB\Driver\Query($filter,$options);+ }; @# d2 j4 @1 X: w
- $cursors = $manager->executeQuery('football.football_Competition_season_matches', $querys);/ H" d# Y; g- p% `3 h/ G
- $schedule= mg_querys($cursors);, P, q8 v+ A: l* h
- print_r($schedule);% g) K- o) P7 q, d, ~
复制代码 ) y4 t' l0 Y" l
2 R+ y6 [' ^7 }
~7 V' L. K: S* O9 c- B, |) H6 d" S8 l. C% G9 O: @, b
------------------------------------------------------------------------------------- 一、更新前通过控制台查看数据,查看命令如下 db.sites.find().pretty() 二、通过php实现数据更新,代码如下 <?php // 1.创建数据库连接对象 $manager = new MongoDB\Driver\Manager("mongodb://localhost:27017"); % z0 `) _3 i9 a. u; g/ S
// 2.创建数据更新对象 $bulk = new MongoDB\Driver\BulkWrite; // 说明:更新index=2的数据,把原来的url更新为现在的内容,multi:只更新匹配到的第一条数据 $bulk->update( ['index' => 2], ['$set' => ['url' => 'https://www.java.com']], ['multi' => false, 'upsert' => false] ); 3 h; ]" O% L% T) n5 a
// 3.创建更新操作级别对象 // 说明:MongoDB\Driver\WriteConcern::MAJORITY :抛出网络错误异常、服务器错误异常;并等待一个主服务器完成写操作 // 1000:等待超时时间 $writeConcern = new MongoDB\Driver\WriteConcern(MongoDB\Driver\WriteConcern::MAJORITY, 1000);
: t4 H4 r: |3 X! r// 4.执行写命令 // 说明:test.sites是test库下的sites集合 // $bulk:更新对象 // $writeConcern:写操作保证级别 $result = $manager->executeBulkWrite('test.sites', $bulk, $writeConcern); $ u7 R: d! U5 q, A
// 5.输出更新后的结果 var_dump($result); 代码截图如下: 运行结果截图如下: 三、通过控制台查看更新后的数据,查看命令如下 db.sites.find().pretty() $ |5 x8 {0 I/ j# F5 k, z3 E
/ L8 B2 m1 ~, E |