查询操作 9 A! Y$ f) t# i( C( t5 T7 V
- $filter["season_id"] = 106;& S6 s# n& b2 z g1 B6 X
- //$filter["array.8"] = 'cml123';; `! c% C, l$ G" a' e: ]& R
z1 @4 o8 L2 s% A- $filter = ["matches.events_id"=>1];
- R% ?, v4 t3 D3 ?
* a; ]5 X3 |+ z6 |& s- $filter = ["matches.events_id"=>['$in'=>[2,3,4,5,7]]];8 P0 x! X. B- l7 K5 S Z$ n7 {
- $filter = ["matches.events_id"=>['$lt'=>'8'];
) |1 `" P! N4 e$ ]) s - 1 {3 ]" |$ K# W
7 a4 E) Y3 }2 v5 {! M6 H6 N- 以上条件说明 http://bbs.cncml.com/forum.php?m ... &extra=page%3D1
2 m3 }& \" U0 q0 `/ \ - 2 Z* z, Q' b' M& Y$ z9 x" `" {' g
- $options = [
* m5 u% |) F/ d- l( A, a3 h, y - 'projection' => ['_id' => 0,"s_lastid" => 1],+ g' _4 Z' \; l' R
- 'limit' => 1, //显示条数
8 u: {/ \6 X7 _& c2 L; N7 o2 W - 'skip' => 1 //跳过几条 U5 X4 }( w5 Y- K% m W) h! a
- ];. ?( h! W1 z( S6 y9 r. Q
% }, U4 r8 C* V' r/ j2 J$ |- $querys = new MongoDB\Driver\Query($filter,$options);
" E) n* G' |0 I - $cursors = $manager->executeQuery('football.football_Competition_season_matches', $querys);
3 M6 _$ u8 v% S& B0 I! j7 U0 }2 I - $schedule= mg_querys($cursors);$ k8 t* o: V& O6 R, Z, L
- print_r($schedule);
c) Z7 o8 O5 U. V& n$ e7 U
复制代码 8 L0 `' I: \+ P% r( W8 H6 e
9 c# D2 D: F7 v5 m% y
& O. L" E5 t% X7 L. K8 u( X1 k# B: I/ q h a
------------------------------------------------------------------------------------- 一、更新前通过控制台查看数据,查看命令如下 db.sites.find().pretty() 二、通过php实现数据更新,代码如下 <?php // 1.创建数据库连接对象 $manager = new MongoDB\Driver\Manager("mongodb://localhost:27017"); * p. \- }% }- r% ~ u8 \
// 2.创建数据更新对象 $bulk = new MongoDB\Driver\BulkWrite; // 说明:更新index=2的数据,把原来的url更新为现在的内容,multi:只更新匹配到的第一条数据 $bulk->update( ['index' => 2], ['$set' => ['url' => 'https://www.java.com']], ['multi' => false, 'upsert' => false] ); 2 T8 h. B# Y' w$ a0 e
// 3.创建更新操作级别对象 // 说明:MongoDB\Driver\WriteConcern::MAJORITY :抛出网络错误异常、服务器错误异常;并等待一个主服务器完成写操作 // 1000:等待超时时间 $writeConcern = new MongoDB\Driver\WriteConcern(MongoDB\Driver\WriteConcern::MAJORITY, 1000); {' X5 j* z8 t. g& e
// 4.执行写命令 // 说明:test.sites是test库下的sites集合 // $bulk:更新对象 // $writeConcern:写操作保证级别 $result = $manager->executeBulkWrite('test.sites', $bulk, $writeConcern); & w7 D$ p1 i' Z; ~
// 5.输出更新后的结果 var_dump($result); 代码截图如下: 运行结果截图如下: 三、通过控制台查看更新后的数据,查看命令如下 db.sites.find().pretty()
5 O D3 w+ h) |5 r5 x) }7 w
+ u* \! m# T& E3 _. r |