|
查询操作
1 J" ]; ^6 g: I8 q) d" N$ U/ I- $filter["season_id"] = 106;
- k* M+ h0 b S0 p! q - //$filter["array.8"] = 'cml123';/ P4 L& d2 ]7 F7 D" ^
3 \: \# R! F* T8 R- $filter = ["matches.events_id"=>1];
( Y" ?0 f- f% M - 5 N Y+ D1 [- a$ V2 D4 d
- $filter = ["matches.events_id"=>['$in'=>[2,3,4,5,7]]];( t' y! c( j0 \' S* ]) `2 q' R
- $filter = ["matches.events_id"=>['$lt'=>'8'];
`0 l# E: g' \5 O3 p. t3 E
+ a6 Z- \) _' j3 s) }$ V( }; Y
' Y; m" d, j" b# }- O* N3 p* F- 以上条件说明 http://bbs.cncml.com/forum.php?m ... &extra=page%3D1
7 g# H* J+ ?, _1 s2 m0 z1 G
; X+ L, A7 R" T( K6 W5 A* i4 t/ \- $options = [
) a; k, Y8 v7 } - 'projection' => ['_id' => 0,"s_lastid" => 1],7 {0 b+ L0 X; [
- 'limit' => 1, //显示条数
2 G7 B6 y4 }% t- d( e - 'skip' => 1 //跳过几条
4 \" @; M' t8 K! h. S5 t - ];
, R% q$ `3 R( U" f; M' e, y$ n# k - 4 [8 A. h' g3 U
- $querys = new MongoDB\Driver\Query($filter,$options);# z- W# A% ^- J% g
- $cursors = $manager->executeQuery('football.football_Competition_season_matches', $querys);( W. p6 ^( W' ^7 z- F8 j; ~. e8 M k
- $schedule= mg_querys($cursors);
( f k7 q& r: z- Q - print_r($schedule);( L6 Y) {6 w" C9 U: P
复制代码 ; X. B# J0 @( L* p1 u: Y3 I
. f2 I& H7 w' B" n- l, j; a- h
2 P& m% v! _9 _
9 T. X3 |3 g& g------------------------------------------------------------------------------------- 一、更新前通过控制台查看数据,查看命令如下 db.sites.find().pretty() 二、通过php实现数据更新,代码如下 <?php // 1.创建数据库连接对象 $manager = new MongoDB\Driver\Manager("mongodb://localhost:27017"); y9 J& e4 ^7 F, R# ~* f0 Q
// 2.创建数据更新对象 $bulk = new MongoDB\Driver\BulkWrite; // 说明:更新index=2的数据,把原来的url更新为现在的内容,multi:只更新匹配到的第一条数据 $bulk->update( ['index' => 2], ['$set' => ['url' => 'https://www.java.com']], ['multi' => false, 'upsert' => false] );
* c# _! g8 B, s5 [) N, {0 _6 R% u// 3.创建更新操作级别对象 // 说明:MongoDB\Driver\WriteConcern::MAJORITY :抛出网络错误异常、服务器错误异常;并等待一个主服务器完成写操作 // 1000:等待超时时间 $writeConcern = new MongoDB\Driver\WriteConcern(MongoDB\Driver\WriteConcern::MAJORITY, 1000);
4 O6 E% T, S# U" h* N7 t) K1 _// 4.执行写命令 // 说明:test.sites是test库下的sites集合 // $bulk:更新对象 // $writeConcern:写操作保证级别 $result = $manager->executeBulkWrite('test.sites', $bulk, $writeConcern); ' r/ z/ x) F/ n& z1 c- U
// 5.输出更新后的结果 var_dump($result); 代码截图如下: 运行结果截图如下: 三、通过控制台查看更新后的数据,查看命令如下 db.sites.find().pretty() 9 ~, F$ W) E0 F: o1 ?7 H
8 f; E. {; h, }, F' ]) L% ^
|