|
查询操作 8 l" d: y* ?" x* u) S
- $filter["season_id"] = 106;
$ [+ X# `" L$ e - //$filter["array.8"] = 'cml123';3 E: p( h s1 t8 Y, P; e
5 f0 t0 h( }# V4 b- $filter = ["matches.events_id"=>1];1 X1 Q" D# x0 Y( _9 I+ o/ c: S
, H' ~) g7 M7 f$ ^: J9 I: o) B9 ]- $filter = ["matches.events_id"=>['$in'=>[2,3,4,5,7]]];( ]3 ]# d$ k! z$ \
- $filter = ["matches.events_id"=>['$lt'=>'8'];# }' F2 W! e/ o+ @
- ! K7 ~' N- B) U
5 G1 A" s$ Z3 ~; s' c& C* G- 以上条件说明 http://bbs.cncml.com/forum.php?m ... &extra=page%3D1
. N9 f3 }! [$ _7 C; v
0 { _! b( J( x0 h- $options = [! t8 L: i# q; t' p x& n
- 'projection' => ['_id' => 0,"s_lastid" => 1],& C4 i. B8 Z4 m& f
- 'limit' => 1, //显示条数
) e# \! `) ]8 |: D. D* t- i - 'skip' => 1 //跳过几条% o( W- {5 p- g( l- j
- ];4 u h$ x! {( E6 S% F9 h F3 }7 z
- N4 o; v7 c( S; m) w: S* u+ X1 o
- $querys = new MongoDB\Driver\Query($filter,$options);2 T Q* M+ H! B# }, \1 @/ w3 f! z
- $cursors = $manager->executeQuery('football.football_Competition_season_matches', $querys);
9 t* M B" G' P3 T) E - $schedule= mg_querys($cursors);
5 r6 n. H' _ D& a& @ - print_r($schedule);+ y4 A; ]/ f1 S' r# Q6 m
复制代码
/ r' R! y6 L6 S+ g5 U # j1 M; b% `' H7 v% E
8 C' ^/ H- C M, P% l; h# i
1 [' m# T5 g# }! u5 _6 T------------------------------------------------------------------------------------- 一、更新前通过控制台查看数据,查看命令如下 db.sites.find().pretty() 二、通过php实现数据更新,代码如下 <?php // 1.创建数据库连接对象 $manager = new MongoDB\Driver\Manager("mongodb://localhost:27017");
1 |5 G0 C. ]2 h4 U// 2.创建数据更新对象 $bulk = new MongoDB\Driver\BulkWrite; // 说明:更新index=2的数据,把原来的url更新为现在的内容,multi:只更新匹配到的第一条数据 $bulk->update( ['index' => 2], ['$set' => ['url' => 'https://www.java.com']], ['multi' => false, 'upsert' => false] ); & p, P: V6 _3 |# l7 b
// 3.创建更新操作级别对象 // 说明:MongoDB\Driver\WriteConcern::MAJORITY :抛出网络错误异常、服务器错误异常;并等待一个主服务器完成写操作 // 1000:等待超时时间 $writeConcern = new MongoDB\Driver\WriteConcern(MongoDB\Driver\WriteConcern::MAJORITY, 1000); n+ M' }- f, u" X) y& p
// 4.执行写命令 // 说明:test.sites是test库下的sites集合 // $bulk:更新对象 // $writeConcern:写操作保证级别 $result = $manager->executeBulkWrite('test.sites', $bulk, $writeConcern); - A; e3 e3 y* j! W
// 5.输出更新后的结果 var_dump($result); 代码截图如下: 运行结果截图如下: 三、通过控制台查看更新后的数据,查看命令如下 db.sites.find().pretty() - @' z4 S: n9 B P9 |& y
9 S; j3 l+ t, G; Y9 @7 t3 A- e |