查询操作 ' V; E* U' z. K
- $filter["season_id"] = 106;
) d3 T7 H6 g1 I+ H( K @ - //$filter["array.8"] = 'cml123';. {( \* o/ j! _. W9 h& i0 P
) `: t' r( \0 a) ~5 n1 P" D- $filter = ["matches.events_id"=>1];2 ^( H; S1 g% t
- # L" k. p3 V8 w# G' @# g1 O
- $filter = ["matches.events_id"=>['$in'=>[2,3,4,5,7]]];" f: I& N& }# s% U0 C$ ~8 n4 {. B- P0 Z9 e
- $filter = ["matches.events_id"=>['$lt'=>'8'];3 ~6 x- f S u
- 1 D7 v; z( F' E2 q$ ]
- 4 p# ^2 w ?8 Y9 V$ }% ]7 ?! f
- 以上条件说明 http://bbs.cncml.com/forum.php?m ... &extra=page%3D1
* S% Z6 a0 g- A: W
. d1 `% v7 R- W5 C" T$ u+ U- $options = [/ x, } P; d4 x- z% P% d- ]& J7 f
- 'projection' => ['_id' => 0,"s_lastid" => 1],2 b) q1 p( L, x4 Q" `; H! c. W
- 'limit' => 1, //显示条数4 ^3 G' `3 n1 W2 k
- 'skip' => 1 //跳过几条* [7 A3 X: d0 h3 V, g
- ];! H1 K; x0 P. T* h
9 V/ q( O/ G D$ b- $querys = new MongoDB\Driver\Query($filter,$options);
+ n* W W1 _) L5 S v/ q - $cursors = $manager->executeQuery('football.football_Competition_season_matches', $querys);
4 U! Q8 M: ~9 M! o, a$ | - $schedule= mg_querys($cursors);9 H" b4 L" A% X& H' A% Y! ~% S
- print_r($schedule);' X; H" O+ X; a
复制代码 , W9 c, O4 k+ \' [7 |7 ?" _! ~
! m1 P/ U9 \. b& V( h* w s6 R9 y. y- w+ M6 }: L" v; Y; J; i% J( s9 w
. L+ n5 a4 J( C------------------------------------------------------------------------------------- 一、更新前通过控制台查看数据,查看命令如下 db.sites.find().pretty() 二、通过php实现数据更新,代码如下 <?php // 1.创建数据库连接对象 $manager = new MongoDB\Driver\Manager("mongodb://localhost:27017"); ) E" R% s7 o4 j
// 2.创建数据更新对象 $bulk = new MongoDB\Driver\BulkWrite; // 说明:更新index=2的数据,把原来的url更新为现在的内容,multi:只更新匹配到的第一条数据 $bulk->update( ['index' => 2], ['$set' => ['url' => 'https://www.java.com']], ['multi' => false, 'upsert' => false] ); . e+ d& p0 S. }
// 3.创建更新操作级别对象 // 说明:MongoDB\Driver\WriteConcern::MAJORITY :抛出网络错误异常、服务器错误异常;并等待一个主服务器完成写操作 // 1000:等待超时时间 $writeConcern = new MongoDB\Driver\WriteConcern(MongoDB\Driver\WriteConcern::MAJORITY, 1000);
' g' a( @1 I( b, d4 |, @ p// 4.执行写命令 // 说明:test.sites是test库下的sites集合 // $bulk:更新对象 // $writeConcern:写操作保证级别 $result = $manager->executeBulkWrite('test.sites', $bulk, $writeConcern); 3 v! r2 t+ g6 g& H: ?" q! y* N
// 5.输出更新后的结果 var_dump($result); 代码截图如下: 运行结果截图如下: 三、通过控制台查看更新后的数据,查看命令如下 db.sites.find().pretty()
& e: D! K( A/ [1 u* o) {9 {" k) m7 l: B
|