|
查询操作
( B7 u7 U+ K i- Z7 p- $filter["season_id"] = 106;1 G3 \0 u$ S5 |% T$ h3 ^8 g
- //$filter["array.8"] = 'cml123';1 p( ]7 ?4 ? M2 ?9 a$ h
- - H0 N: ]. l# U* A3 j& h8 j
- $filter = ["matches.events_id"=>1];
' {* C+ {) n5 o+ N4 _! W' t - ) E, Z: d2 |3 K, o
- $filter = ["matches.events_id"=>['$in'=>[2,3,4,5,7]]];! Y3 d4 ~4 N( y
- $filter = ["matches.events_id"=>['$lt'=>'8'];
+ R2 W) l- r& }5 t( l# ~" B
/ G9 _# A2 _2 c; V. Q/ r
) \- S d. G/ c* v- 以上条件说明 http://bbs.cncml.com/forum.php?m ... &extra=page%3D1) p6 H" x/ I$ }" [3 G$ D
- ( E0 b% k9 |5 w
- $options = [
' Z# O0 I1 ^ x( G1 @ - 'projection' => ['_id' => 0,"s_lastid" => 1],& u5 A0 D; K) M _
- 'limit' => 1, //显示条数- I) z9 m' W7 u9 |7 M5 ^
- 'skip' => 1 //跳过几条* X/ k9 i1 N- g2 g- A+ A
- ];
4 H3 |) z) [5 S! q9 a5 T - / }$ [9 F% P( v( J9 [
- $querys = new MongoDB\Driver\Query($filter,$options);: c: M5 p: M3 l' d0 s6 p
- $cursors = $manager->executeQuery('football.football_Competition_season_matches', $querys);
4 P4 @: ~' L, [- P9 c - $schedule= mg_querys($cursors);
5 u: }6 n) _& a+ I5 e - print_r($schedule);2 w) p8 n. x c$ q' }! t: p$ @% i
复制代码
0 X. o6 r6 x- x. n0 {* ]3 \5 m/ ] . C- b: w `: E! S
$ ]9 R R: b! e# s8 l4 R) \; V) H* U$ n7 R" v
------------------------------------------------------------------------------------- 一、更新前通过控制台查看数据,查看命令如下 db.sites.find().pretty() 二、通过php实现数据更新,代码如下 <?php // 1.创建数据库连接对象 $manager = new MongoDB\Driver\Manager("mongodb://localhost:27017"); . o. [/ t1 M4 r; k0 C) X' i9 B
// 2.创建数据更新对象 $bulk = new MongoDB\Driver\BulkWrite; // 说明:更新index=2的数据,把原来的url更新为现在的内容,multi:只更新匹配到的第一条数据 $bulk->update( ['index' => 2], ['$set' => ['url' => 'https://www.java.com']], ['multi' => false, 'upsert' => false] );
" I% T' Q5 B4 D' j// 3.创建更新操作级别对象 // 说明:MongoDB\Driver\WriteConcern::MAJORITY :抛出网络错误异常、服务器错误异常;并等待一个主服务器完成写操作 // 1000:等待超时时间 $writeConcern = new MongoDB\Driver\WriteConcern(MongoDB\Driver\WriteConcern::MAJORITY, 1000); / q, d. u0 x3 j2 x) D# `
// 4.执行写命令 // 说明:test.sites是test库下的sites集合 // $bulk:更新对象 // $writeConcern:写操作保证级别 $result = $manager->executeBulkWrite('test.sites', $bulk, $writeConcern); ! G: n! k" f4 g
// 5.输出更新后的结果 var_dump($result); 代码截图如下: 运行结果截图如下: 三、通过控制台查看更新后的数据,查看命令如下 db.sites.find().pretty() + d1 e3 D& h& L( D
. G% t4 O7 Q4 e
|