查询操作 8 M* {% p$ O) ?; U \ ]) L
- $filter["season_id"] = 106;
2 l' N8 i2 r( g; L8 A - //$filter["array.8"] = 'cml123';
- {( d5 W L! |# ~4 D0 J2 z, b - : e' {: h2 w5 \" e) S2 v" s
- $filter = ["matches.events_id"=>1];
3 w! ?" ^4 ^' O0 v6 j/ k - h7 i. O" C7 W4 P
- $filter = ["matches.events_id"=>['$in'=>[2,3,4,5,7]]];, a i! ^) a; u4 C: ^
- $filter = ["matches.events_id"=>['$lt'=>'8'];
/ k( K! M$ M2 A6 i
7 t/ J. d% g6 a
7 p3 x. v% a7 h5 Z( u$ Z- 以上条件说明 http://bbs.cncml.com/forum.php?m ... &extra=page%3D1
* }8 w4 x! E) ^' I+ p* t1 G q
6 C k5 N+ N }: l" y- $options = [
2 L' |0 G7 B& `9 x+ X7 v8 P* L# S z - 'projection' => ['_id' => 0,"s_lastid" => 1],) D% u" l9 f9 `1 G8 `; H
- 'limit' => 1, //显示条数
8 t$ b; I8 D) M$ \, { - 'skip' => 1 //跳过几条
' D5 x. d& Q1 ] - ];
+ z) N. m' v! Y - 0 E( l! \* q: D1 ?9 u7 G
- $querys = new MongoDB\Driver\Query($filter,$options); B) H3 u# L' r1 d3 V
- $cursors = $manager->executeQuery('football.football_Competition_season_matches', $querys);8 N7 s3 e6 O7 s J3 _7 C, y0 V$ {
- $schedule= mg_querys($cursors);! e) i1 D; ?4 m3 ^% C
- print_r($schedule);
2 j; V( |- ]6 R$ C0 T% M
复制代码 ( t( M5 p% W/ i% G3 y
' K8 p. c. }4 U0 z1 i+ b b$ S" U$ ~
8 }- f/ ^0 N# t, r% i! }3 v1 Z& p6 g w
------------------------------------------------------------------------------------- 一、更新前通过控制台查看数据,查看命令如下 db.sites.find().pretty() 二、通过php实现数据更新,代码如下 <?php // 1.创建数据库连接对象 $manager = new MongoDB\Driver\Manager("mongodb://localhost:27017");
& ~/ {& d" r/ w; f; r$ c: 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] );
' C. L2 U6 N9 C9 \// 3.创建更新操作级别对象 // 说明:MongoDB\Driver\WriteConcern::MAJORITY :抛出网络错误异常、服务器错误异常;并等待一个主服务器完成写操作 // 1000:等待超时时间 $writeConcern = new MongoDB\Driver\WriteConcern(MongoDB\Driver\WriteConcern::MAJORITY, 1000);
* S- M @2 b9 i; s. B! B1 |// 4.执行写命令 // 说明:test.sites是test库下的sites集合 // $bulk:更新对象 // $writeConcern:写操作保证级别 $result = $manager->executeBulkWrite('test.sites', $bulk, $writeConcern); $ ^- b0 h; A2 j
// 5.输出更新后的结果 var_dump($result); 代码截图如下: 运行结果截图如下: 三、通过控制台查看更新后的数据,查看命令如下 db.sites.find().pretty() / {9 p- f3 f# y1 _0 X n
/ g& j# s$ P8 [7 \ |