|
查询操作
% a& C* G! k0 y- r( t( m' f- $filter["season_id"] = 106;' n* o2 b0 K' E: u8 A
- //$filter["array.8"] = 'cml123';
4 J4 W$ B9 d7 B7 l K- Z
. t7 N" W+ T% [+ Q5 W, u* j: j- $filter = ["matches.events_id"=>1];9 b. D3 ]0 A- i- L7 n# B
- 2 Y# q% y. o: `- x5 P
- $filter = ["matches.events_id"=>['$in'=>[2,3,4,5,7]]];. I% s! P H9 j+ p8 p
- $filter = ["matches.events_id"=>['$lt'=>'8'];
T& t; y! u& a6 S0 C3 X4 l
- R* S% c# t' ?
5 C& u+ @& R+ Z$ d2 Y9 G9 B5 k/ e) v- 以上条件说明 http://bbs.cncml.com/forum.php?m ... &extra=page%3D1
% W% P7 D- d6 m/ T# f# a - ( R% O5 L, s. x- r% s7 u$ W
- $options = [
. l* j, }+ O* i( s4 W6 p - 'projection' => ['_id' => 0,"s_lastid" => 1],9 d+ O; |" r; a" }1 K
- 'limit' => 1, //显示条数; `( [6 Q1 c0 n% Z$ R h8 V; T+ J
- 'skip' => 1 //跳过几条) J/ I- _9 w8 r" e y/ @0 w* i# @
- ];
9 ~. r: E2 g6 e5 H" j
. P! r% r* O' B+ `9 ~- $querys = new MongoDB\Driver\Query($filter,$options);
- A9 i; N' J6 g/ k' I2 H* Y - $cursors = $manager->executeQuery('football.football_Competition_season_matches', $querys);
1 M8 t+ C. ] p8 S, I - $schedule= mg_querys($cursors);
) L8 B1 j- W% v - print_r($schedule);
) }# ~* q, n, g4 ~+ L: t k
复制代码 5 K3 l: K' n" [+ Z0 H, V, @
3 M7 S& y3 v/ ~0 h# q: \2 D' Y& a
* p$ ~. t! U/ Y% H6 y& _; S) C; V& K' m! z9 w
------------------------------------------------------------------------------------- 一、更新前通过控制台查看数据,查看命令如下 db.sites.find().pretty() 二、通过php实现数据更新,代码如下 <?php // 1.创建数据库连接对象 $manager = new MongoDB\Driver\Manager("mongodb://localhost:27017");
+ g! h7 c. w. f- k$ \// 2.创建数据更新对象 $bulk = new MongoDB\Driver\BulkWrite; // 说明:更新index=2的数据,把原来的url更新为现在的内容,multi:只更新匹配到的第一条数据 $bulk->update( ['index' => 2], ['$set' => ['url' => 'https://www.java.com']], ['multi' => false, 'upsert' => false] ); ! _- L4 L0 C% n* S
// 3.创建更新操作级别对象 // 说明:MongoDB\Driver\WriteConcern::MAJORITY :抛出网络错误异常、服务器错误异常;并等待一个主服务器完成写操作 // 1000:等待超时时间 $writeConcern = new MongoDB\Driver\WriteConcern(MongoDB\Driver\WriteConcern::MAJORITY, 1000);
3 e1 V' O( y5 `& s8 U// 4.执行写命令 // 说明:test.sites是test库下的sites集合 // $bulk:更新对象 // $writeConcern:写操作保证级别 $result = $manager->executeBulkWrite('test.sites', $bulk, $writeConcern);
* I5 h0 ^3 g1 e- M, m" \4 u% d// 5.输出更新后的结果 var_dump($result); 代码截图如下: 运行结果截图如下: 三、通过控制台查看更新后的数据,查看命令如下 db.sites.find().pretty() ) y- a- z3 y7 l8 J9 c1 l/ ?7 i
9 o9 e: w: z) m3 Y# C
|