|
查询操作 % `- e' k. f" S+ [3 V4 i# ~
- $filter["season_id"] = 106;
! _+ D5 h* B8 Y `3 u - //$filter["array.8"] = 'cml123';
4 J/ i6 d' I! x0 k& X) L - R+ h4 \- {' ?! d4 U) |, F
- $filter = ["matches.events_id"=>1];! l8 u! D3 m7 {/ \. _
- # ?; N% G3 c% @" t" J
- $filter = ["matches.events_id"=>['$in'=>[2,3,4,5,7]]];, q6 F+ R" y; f2 ?
- $filter = ["matches.events_id"=>['$lt'=>'8'];" S; U5 p9 E* V$ S& @4 }
! F% X4 l% Z2 [$ U- 4 z( G2 r x6 \5 h8 r! E1 S
- 以上条件说明 http://bbs.cncml.com/forum.php?m ... &extra=page%3D1
* @# j/ T, I9 g7 k5 I( C/ d
6 @; L4 P; J6 u! N, n" `# @- $options = [7 S8 {! ^ _( b
- 'projection' => ['_id' => 0,"s_lastid" => 1],
, {8 q: T4 @6 _ S. x - 'limit' => 1, //显示条数, R7 z8 K% M P# e- w
- 'skip' => 1 //跳过几条
/ z( S$ E) @- Y( ~8 u - ];, \7 F* R. J* A/ _1 Z6 I
- . K* m( i. n0 d/ q. [
- $querys = new MongoDB\Driver\Query($filter,$options);
" X C8 W3 m, f% _8 v( u - $cursors = $manager->executeQuery('football.football_Competition_season_matches', $querys);
* n. p g8 ^) E# m$ O - $schedule= mg_querys($cursors);; Q. K6 }$ f( |1 D; A. ?. c
- print_r($schedule);
& Y% m" h" e, `: [3 `
复制代码 ( x9 f+ J/ L3 g) B4 x# [
9 D5 ^4 a. d* F; b
- \0 t9 ?8 ?- E! t
7 S5 V& H0 U! n8 E! a- H1 O) e8 E------------------------------------------------------------------------------------- 一、更新前通过控制台查看数据,查看命令如下 db.sites.find().pretty() 二、通过php实现数据更新,代码如下 <?php // 1.创建数据库连接对象 $manager = new MongoDB\Driver\Manager("mongodb://localhost:27017");
# ~4 g: i3 F' p' e a; J// 2.创建数据更新对象 $bulk = new MongoDB\Driver\BulkWrite; // 说明:更新index=2的数据,把原来的url更新为现在的内容,multi:只更新匹配到的第一条数据 $bulk->update( ['index' => 2], ['$set' => ['url' => 'https://www.java.com']], ['multi' => false, 'upsert' => false] ); 2 t. e! P0 G: t( j. C! H% n# `" A; J
// 3.创建更新操作级别对象 // 说明:MongoDB\Driver\WriteConcern::MAJORITY :抛出网络错误异常、服务器错误异常;并等待一个主服务器完成写操作 // 1000:等待超时时间 $writeConcern = new MongoDB\Driver\WriteConcern(MongoDB\Driver\WriteConcern::MAJORITY, 1000); ) N7 ?/ C, @% Y' o% G) ]
// 4.执行写命令 // 说明:test.sites是test库下的sites集合 // $bulk:更新对象 // $writeConcern:写操作保证级别 $result = $manager->executeBulkWrite('test.sites', $bulk, $writeConcern);
W4 a5 ]6 V4 X" z& ^. s// 5.输出更新后的结果 var_dump($result); 代码截图如下: 运行结果截图如下: 三、通过控制台查看更新后的数据,查看命令如下 db.sites.find().pretty()
$ f' ?7 S4 I& e+ v1 ?! O; P5 X/ W: k5 x
|