查询操作
# b: d$ _+ p* e2 R5 p* Z9 w' ^ q- $filter["season_id"] = 106;" N3 q' w0 B j6 R% t
- //$filter["array.8"] = 'cml123';7 U; o" E7 \2 F
/ a! j2 G- f: p2 Y, ?; \- $filter = ["matches.events_id"=>1];
4 b0 C( b1 [2 Q( O) K
9 s$ i8 p' v5 l8 b9 f, O9 P- $filter = ["matches.events_id"=>['$in'=>[2,3,4,5,7]]];% O' X2 W/ G# S% ^* o4 o9 R
- $filter = ["matches.events_id"=>['$lt'=>'8'];1 F# X3 c c/ e' M. s1 \0 f" o- v3 o+ K
- ! m, h# s9 }: g6 a! P& R% _* d
: L9 u$ H5 h/ r6 p3 b& G3 j& A2 Y- 以上条件说明 http://bbs.cncml.com/forum.php?m ... &extra=page%3D1
- n& D4 n4 B" V1 \ [3 { - 2 o8 A& M; @* ]" [- b2 o% i$ M
- $options = [
" `- U# b7 U$ G2 x; Y3 u$ R - 'projection' => ['_id' => 0,"s_lastid" => 1],
' J# B p9 ~7 J, | - 'limit' => 1, //显示条数
) f$ O5 E* q3 y - 'skip' => 1 //跳过几条4 Y' e+ D8 t9 i2 F" [
- ];% w/ x* x. G9 O; \0 ^) W6 ^7 J$ d4 t
- 7 _. M' n. ?5 ?4 ^* ^& }! X
- $querys = new MongoDB\Driver\Query($filter,$options);/ ]3 m9 P9 c$ r* u+ }1 t
- $cursors = $manager->executeQuery('football.football_Competition_season_matches', $querys);; Q% g2 W$ B) [2 b
- $schedule= mg_querys($cursors);
% t2 E9 a0 Y+ q - print_r($schedule);
. V6 D( _$ F- {+ \4 D, O
复制代码 ' a9 ?' `# a- Y' }: K
4 V8 B: }& L1 A! A6 a
5 V7 ~& |% x. x {
6 y* g' A0 S, e/ {------------------------------------------------------------------------------------- 一、更新前通过控制台查看数据,查看命令如下 db.sites.find().pretty() 二、通过php实现数据更新,代码如下 <?php // 1.创建数据库连接对象 $manager = new MongoDB\Driver\Manager("mongodb://localhost:27017");
3 M3 d3 D% P/ {! J8 e// 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 J* C1 l% C. C2 o3 d# u
// 3.创建更新操作级别对象 // 说明:MongoDB\Driver\WriteConcern::MAJORITY :抛出网络错误异常、服务器错误异常;并等待一个主服务器完成写操作 // 1000:等待超时时间 $writeConcern = new MongoDB\Driver\WriteConcern(MongoDB\Driver\WriteConcern::MAJORITY, 1000);
+ L' b& Z% w: _. _2 K( \6 d- E// 4.执行写命令 // 说明:test.sites是test库下的sites集合 // $bulk:更新对象 // $writeConcern:写操作保证级别 $result = $manager->executeBulkWrite('test.sites', $bulk, $writeConcern); - T8 ?2 t" O( Q3 x- |( G# K
// 5.输出更新后的结果 var_dump($result); 代码截图如下: 运行结果截图如下: 三、通过控制台查看更新后的数据,查看命令如下 db.sites.find().pretty() ! U; s# k* h" H& r. d
' |. Z# }3 p; M/ a$ L# ~ |