|
查询操作 " r1 u% c; L8 W0 [2 n+ | E" D1 O, W
- $filter["season_id"] = 106;
E Q5 a7 T- Y' [# X }4 h1 G - //$filter["array.8"] = 'cml123';. ~% `' c" i5 ~: q, X7 c# |# ^
- $ y P" {) S: \
- $filter = ["matches.events_id"=>1];
9 x# u6 u( U7 _# R - ( |* C- j8 R: _$ \: u6 I
- $filter = ["matches.events_id"=>['$in'=>[2,3,4,5,7]]];
& a1 g( G6 J" v6 `5 a - $filter = ["matches.events_id"=>['$lt'=>'8'];9 F! b2 c) H$ \0 X; l) n, W
- t9 U4 p# d' {6 D, f4 X
% R! t* {/ [% k0 A' S- 以上条件说明 http://bbs.cncml.com/forum.php?m ... &extra=page%3D1
2 _) I) G+ |- ^, z5 v ]! z, F1 [
) |! N/ ?; `+ [3 i: l0 Q- $options = [
6 h' D; J( I; f# P - 'projection' => ['_id' => 0,"s_lastid" => 1],
* h6 g E- R; i( |! Z+ O. B8 U0 c1 I - 'limit' => 1, //显示条数2 t: D( d3 \& ?2 \& ~
- 'skip' => 1 //跳过几条, E+ v. ~8 m p
- ];
5 P9 E$ z# X5 I& o
/ [/ |9 T( q5 F, Z! Z+ a' p- $querys = new MongoDB\Driver\Query($filter,$options);
4 B1 o! @! w: I$ Y C$ R. j. d3 G - $cursors = $manager->executeQuery('football.football_Competition_season_matches', $querys);) n7 x" \5 x) Q- H
- $schedule= mg_querys($cursors);
# ?2 J6 Z5 J* n% S - print_r($schedule);
" S+ W; a; `0 C, E) d4 O, U; F5 v
复制代码
! C# e' T/ `9 s# J: g( ^ s, t2 L
' R1 R7 D5 N$ T+ I$ I! t. y' @- d6 S
5 F, _; n8 e) a9 x0 n$ _% f+ Q5 K+ g7 E3 v- n! u N$ M. o
------------------------------------------------------------------------------------- 一、更新前通过控制台查看数据,查看命令如下 db.sites.find().pretty() 二、通过php实现数据更新,代码如下 <?php // 1.创建数据库连接对象 $manager = new MongoDB\Driver\Manager("mongodb://localhost:27017");
5 K7 V2 |7 k' y- P/ |$ U* S// 2.创建数据更新对象 $bulk = new MongoDB\Driver\BulkWrite; // 说明:更新index=2的数据,把原来的url更新为现在的内容,multi:只更新匹配到的第一条数据 $bulk->update( ['index' => 2], ['$set' => ['url' => 'https://www.java.com']], ['multi' => false, 'upsert' => false] );
+ W3 _/ r0 e5 K: T0 u! V3 u a// 3.创建更新操作级别对象 // 说明:MongoDB\Driver\WriteConcern::MAJORITY :抛出网络错误异常、服务器错误异常;并等待一个主服务器完成写操作 // 1000:等待超时时间 $writeConcern = new MongoDB\Driver\WriteConcern(MongoDB\Driver\WriteConcern::MAJORITY, 1000);
" I+ H- ~3 m# C9 o' R, V3 I, T// 4.执行写命令 // 说明:test.sites是test库下的sites集合 // $bulk:更新对象 // $writeConcern:写操作保证级别 $result = $manager->executeBulkWrite('test.sites', $bulk, $writeConcern);
- x4 `8 w5 b) l+ J8 `7 J; T2 G6 O// 5.输出更新后的结果 var_dump($result); 代码截图如下: 运行结果截图如下: 三、通过控制台查看更新后的数据,查看命令如下 db.sites.find().pretty()
2 J B# `' E- l- ?' ^$ [* p Y. K0 ]0 ~+ |, P# m
|