查询操作
- c, D( f/ f8 D0 |- $filter["season_id"] = 106;
. E3 y; C& c) @; F s. i$ d' S* A6 i X# u - //$filter["array.8"] = 'cml123';$ } A- x7 Z& U0 Z$ s$ _3 Q
& t P2 z7 p/ t- $filter = ["matches.events_id"=>1];+ Q: u$ V0 B1 Y3 L1 y/ Y
4 \) W) {4 v2 {# Y; r* ?- $filter = ["matches.events_id"=>['$in'=>[2,3,4,5,7]]];* W9 {5 Q0 m; E" }: O
- $filter = ["matches.events_id"=>['$lt'=>'8'];
2 t' |3 N6 p6 Y8 f3 ^5 C- V" \ - 0 H9 _( x+ o( ^& a9 C
- % i+ [! s J" m4 b2 S3 N; X
- 以上条件说明 http://bbs.cncml.com/forum.php?m ... &extra=page%3D1
! |( X" O. F" S
E9 k% ?8 `( ?! p2 e5 [! J- $options = [
" I& ?; W5 I7 e - 'projection' => ['_id' => 0,"s_lastid" => 1],% n U* o8 w5 {/ J
- 'limit' => 1, //显示条数
& {9 r1 p1 z8 e - 'skip' => 1 //跳过几条
& y" F( T c+ }; \7 [ - ];+ x/ ~! B8 R: b: b8 n# I, a
- 2 o1 o% |. S" c5 z9 p, o
- $querys = new MongoDB\Driver\Query($filter,$options);
2 s& G2 X( Z# `; F - $cursors = $manager->executeQuery('football.football_Competition_season_matches', $querys);
4 p! K( o3 J* J3 S - $schedule= mg_querys($cursors);
) l0 q' E% ^8 {6 e: d - print_r($schedule);" M8 B5 G7 [/ t; ?, V( _
复制代码 6 Q% c' {- R- m8 r# _& f9 ~$ Q% w
4 j/ s2 I8 U3 t( F4 ^
( s+ k/ [+ M% y l2 s. ?& L1 d$ z& l% d) _
------------------------------------------------------------------------------------- 一、更新前通过控制台查看数据,查看命令如下 db.sites.find().pretty() 二、通过php实现数据更新,代码如下 <?php // 1.创建数据库连接对象 $manager = new MongoDB\Driver\Manager("mongodb://localhost:27017"); . ]# d3 ]1 N" p. Y3 U- O
// 2.创建数据更新对象 $bulk = new MongoDB\Driver\BulkWrite; // 说明:更新index=2的数据,把原来的url更新为现在的内容,multi:只更新匹配到的第一条数据 $bulk->update( ['index' => 2], ['$set' => ['url' => 'https://www.java.com']], ['multi' => false, 'upsert' => false] ); 6 ]) D' k5 K2 z$ R" m
// 3.创建更新操作级别对象 // 说明:MongoDB\Driver\WriteConcern::MAJORITY :抛出网络错误异常、服务器错误异常;并等待一个主服务器完成写操作 // 1000:等待超时时间 $writeConcern = new MongoDB\Driver\WriteConcern(MongoDB\Driver\WriteConcern::MAJORITY, 1000); R( j, ]9 {1 ~1 p# ~) f
// 4.执行写命令 // 说明:test.sites是test库下的sites集合 // $bulk:更新对象 // $writeConcern:写操作保证级别 $result = $manager->executeBulkWrite('test.sites', $bulk, $writeConcern);
( {! {" G7 X, o! }; d// 5.输出更新后的结果 var_dump($result); 代码截图如下: 运行结果截图如下: 三、通过控制台查看更新后的数据,查看命令如下 db.sites.find().pretty() ) o0 u2 G9 g% K! U8 z
7 ~" D9 f5 }# J
|