|
查询操作
" J" ^ }( d* b- $filter["season_id"] = 106;. S7 U; \; n" \ R0 A! f
- //$filter["array.8"] = 'cml123'; v( E: u a" U7 u P
- ! G$ ^5 b6 D- e( s4 @# X* l
- $filter = ["matches.events_id"=>1];
) `1 V7 w1 {. b7 C' `8 ^
3 D6 c. M0 K7 s% }' W1 n0 t. c- $filter = ["matches.events_id"=>['$in'=>[2,3,4,5,7]]];5 b' X; t* S3 X) f$ k# ~; u4 o
- $filter = ["matches.events_id"=>['$lt'=>'8'];& W, d2 E2 y+ [$ a% K1 {
+ K0 x8 q( _8 @: x- x3 a; ]' q
4 a+ I. I* u3 M: c5 [- 以上条件说明 http://bbs.cncml.com/forum.php?m ... &extra=page%3D1, y: B E3 U3 e
- 3 W: E7 z# z# {( R
- $options = [0 {/ u7 Y2 C* E, c
- 'projection' => ['_id' => 0,"s_lastid" => 1],, L, }% K' M% G
- 'limit' => 1, //显示条数
2 P5 ?) T$ @5 `! N1 @) M5 I) M5 u - 'skip' => 1 //跳过几条/ _( V4 s9 B; B; J8 n$ m$ J
- ];/ o3 ?, k1 W$ U9 F% s
- & ] f$ N' [# f3 W# P4 y/ i
- $querys = new MongoDB\Driver\Query($filter,$options);
9 g" s2 v# Y- |, e - $cursors = $manager->executeQuery('football.football_Competition_season_matches', $querys);) R. e/ ^& Z. O5 D6 i9 `& q
- $schedule= mg_querys($cursors);# l: S" x& ^/ h2 Q8 f, Q5 j
- print_r($schedule);
$ N4 z; V9 V! r, w; Z$ T( A+ t
复制代码
4 y0 ~( j6 w' k) c/ x % ]# i/ n) A8 F; O) I( v6 M: W6 T
. O3 l) P5 [& g. A: Z
% |* H$ [2 z O------------------------------------------------------------------------------------- 一、更新前通过控制台查看数据,查看命令如下 db.sites.find().pretty() 二、通过php实现数据更新,代码如下 <?php // 1.创建数据库连接对象 $manager = new MongoDB\Driver\Manager("mongodb://localhost:27017");
c8 V, r+ q$ p6 u3 w1 \# 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] ); 5 i- k$ }- @% D- h0 w! f, y& L
// 3.创建更新操作级别对象 // 说明:MongoDB\Driver\WriteConcern::MAJORITY :抛出网络错误异常、服务器错误异常;并等待一个主服务器完成写操作 // 1000:等待超时时间 $writeConcern = new MongoDB\Driver\WriteConcern(MongoDB\Driver\WriteConcern::MAJORITY, 1000);
& |0 k ?: g5 p% c- [& [// 4.执行写命令 // 说明:test.sites是test库下的sites集合 // $bulk:更新对象 // $writeConcern:写操作保证级别 $result = $manager->executeBulkWrite('test.sites', $bulk, $writeConcern); / X0 O' f. Y4 \9 Q! I% v
// 5.输出更新后的结果 var_dump($result); 代码截图如下: 运行结果截图如下: 三、通过控制台查看更新后的数据,查看命令如下 db.sites.find().pretty() , N0 F8 q2 a) m1 K! l& Y: G
8 g$ G5 E$ b" n9 a0 L, i& r4 S3 [
|