|
查询操作
3 b2 g1 i2 E6 a& F- H* ?6 ?( E' W- $filter["season_id"] = 106;+ u/ T$ V/ V8 r/ {
- //$filter["array.8"] = 'cml123';
2 A8 i9 F, w% c0 X# v
* l) H( t+ B5 F: `( b& Y- $filter = ["matches.events_id"=>1];1 N' X# |; G3 h; _1 O
- # C/ g8 d+ @7 D1 [: |* i
- $filter = ["matches.events_id"=>['$in'=>[2,3,4,5,7]]];
- ]5 k Y2 ?) u3 T1 j - $filter = ["matches.events_id"=>['$lt'=>'8'];6 c# P1 U" c% b/ o7 f- m8 J/ u
' Y, f! o. P0 q1 j7 s* l! e
5 v1 |) h S( I1 I- 以上条件说明 http://bbs.cncml.com/forum.php?m ... &extra=page%3D1
7 @) b+ @) A, S
8 r( _& h8 S, j( y: B- $options = [& V" x( w+ J+ b, l$ m6 Y' u6 r
- 'projection' => ['_id' => 0,"s_lastid" => 1],
5 J _+ O; r# N/ m+ ]% r# o' N) ^ - 'limit' => 1, //显示条数 ~4 V2 d" q) J/ J0 g2 e3 r* f( @
- 'skip' => 1 //跳过几条
" q. l: ^2 t6 a9 f - ];
) z9 l. N" v$ d$ _! i - 0 x6 z$ y7 k- l0 S7 w7 J. k
- $querys = new MongoDB\Driver\Query($filter,$options);
" x! h. ^3 O) B3 S# V" N$ J: r- T; k - $cursors = $manager->executeQuery('football.football_Competition_season_matches', $querys);
4 d( n% F6 N8 Q( F* H - $schedule= mg_querys($cursors);' h" { b! ~6 `
- print_r($schedule);
6 @. Z+ }2 q$ @1 g
复制代码 4 ~9 G( g6 n! b/ N0 p$ _! Z
8 O' c2 X6 l# h1 e4 L3 c9 ^
7 N* U2 [2 G2 t* V- ?. x8 n+ D7 P9 n3 `: c
------------------------------------------------------------------------------------- 一、更新前通过控制台查看数据,查看命令如下 db.sites.find().pretty() 二、通过php实现数据更新,代码如下 <?php // 1.创建数据库连接对象 $manager = new MongoDB\Driver\Manager("mongodb://localhost:27017");
3 l, O) j% m6 i+ \// 2.创建数据更新对象 $bulk = new MongoDB\Driver\BulkWrite; // 说明:更新index=2的数据,把原来的url更新为现在的内容,multi:只更新匹配到的第一条数据 $bulk->update( ['index' => 2], ['$set' => ['url' => 'https://www.java.com']], ['multi' => false, 'upsert' => false] );
, e8 k% i a# W% ]6 X/ h, H* }// 3.创建更新操作级别对象 // 说明:MongoDB\Driver\WriteConcern::MAJORITY :抛出网络错误异常、服务器错误异常;并等待一个主服务器完成写操作 // 1000:等待超时时间 $writeConcern = new MongoDB\Driver\WriteConcern(MongoDB\Driver\WriteConcern::MAJORITY, 1000);
# m( r, X: ~5 E# n// 4.执行写命令 // 说明:test.sites是test库下的sites集合 // $bulk:更新对象 // $writeConcern:写操作保证级别 $result = $manager->executeBulkWrite('test.sites', $bulk, $writeConcern);
9 |; S6 }' r; b# u) q1 Y7 }4 i// 5.输出更新后的结果 var_dump($result); 代码截图如下: 运行结果截图如下: 三、通过控制台查看更新后的数据,查看命令如下 db.sites.find().pretty() 8 Q5 w2 W" B: K6 A$ j, c' g
, F! Q9 I% u+ a9 ]
|