|
查询操作
$ r$ L7 p! |/ R) R- l" |$ o7 t( q- $filter["season_id"] = 106;
# Z4 B# d# d9 v. ~5 p1 P: [% V - //$filter["array.8"] = 'cml123';9 e! s3 h3 q. \1 C
- 5 ]3 {3 W0 g8 ^: [- f. B
- $filter = ["matches.events_id"=>1];. b5 `3 y$ t' ~9 g
- ! m, S/ t* c' o, U+ v4 S
- $filter = ["matches.events_id"=>['$in'=>[2,3,4,5,7]]];6 x% l( Q& { u
- $filter = ["matches.events_id"=>['$lt'=>'8'];
9 @4 o2 g. U S1 \/ [( O: K8 f
* r, X' L5 v+ R% t, ?. c- ( }7 a) [4 } e0 b; A% }% {( I
- 以上条件说明 http://bbs.cncml.com/forum.php?m ... &extra=page%3D1) @* r& a) K# P w( l8 _$ w
- % Q0 F% @* |9 E2 G, T0 l! B
- $options = [$ r8 b( f9 W9 G) X% m
- 'projection' => ['_id' => 0,"s_lastid" => 1],
7 k- z$ q! C1 i* ]" T; e; A7 u* L - 'limit' => 1, //显示条数
6 {# J( S/ M: ^/ a* O9 `; h - 'skip' => 1 //跳过几条, J/ X F; T; h" ?
- ];
: D2 ]& x1 w9 @" M9 z' T- J
E. z- s* u, y4 j" w- $querys = new MongoDB\Driver\Query($filter,$options);+ L V) g/ I M$ f0 e! e* s. D
- $cursors = $manager->executeQuery('football.football_Competition_season_matches', $querys);
' g' D, u3 \) L2 ^ U - $schedule= mg_querys($cursors);
" h1 S8 i, H: P" | - print_r($schedule);, R# n8 {; a% i; u/ h, c9 I
复制代码
) d* L% O7 e) D7 s4 ] . A/ v6 P0 L& D c: E
- _+ z3 m7 W; h9 i- E4 L I
8 [! C( q- m4 c2 p$ f$ [6 X; v------------------------------------------------------------------------------------- 一、更新前通过控制台查看数据,查看命令如下 db.sites.find().pretty() 二、通过php实现数据更新,代码如下 <?php // 1.创建数据库连接对象 $manager = new MongoDB\Driver\Manager("mongodb://localhost:27017"); 6 i2 \5 M1 g6 }2 c# b* a y6 X
// 2.创建数据更新对象 $bulk = new MongoDB\Driver\BulkWrite; // 说明:更新index=2的数据,把原来的url更新为现在的内容,multi:只更新匹配到的第一条数据 $bulk->update( ['index' => 2], ['$set' => ['url' => 'https://www.java.com']], ['multi' => false, 'upsert' => false] );
. l+ ~# t# n1 |// 3.创建更新操作级别对象 // 说明:MongoDB\Driver\WriteConcern::MAJORITY :抛出网络错误异常、服务器错误异常;并等待一个主服务器完成写操作 // 1000:等待超时时间 $writeConcern = new MongoDB\Driver\WriteConcern(MongoDB\Driver\WriteConcern::MAJORITY, 1000);
( w- o6 V4 z9 u& v- g// 4.执行写命令 // 说明:test.sites是test库下的sites集合 // $bulk:更新对象 // $writeConcern:写操作保证级别 $result = $manager->executeBulkWrite('test.sites', $bulk, $writeConcern);
7 S- v) x8 S% H8 Y2 Y* |5 h// 5.输出更新后的结果 var_dump($result); 代码截图如下: 运行结果截图如下: 三、通过控制台查看更新后的数据,查看命令如下 db.sites.find().pretty()
- [1 {% n% R' {0 U e4 C, v; ~
( {& R! Q) y4 m9 Z. k |