|
查询操作
, P$ c, _2 `) c0 o. E9 i0 B6 g- $filter["season_id"] = 106;
0 N# z8 m4 l2 Z, h9 G) A( _ - //$filter["array.8"] = 'cml123';
0 ^9 C5 M5 W/ Y" {- v9 D$ M - ! _6 A3 ^* @2 G$ }2 Y% M
- $filter = ["matches.events_id"=>1];
8 _* l: r" P% F; I# i( Q6 H# y - 0 s; }1 ~0 m2 z* X1 R
- $filter = ["matches.events_id"=>['$in'=>[2,3,4,5,7]]];
6 S6 Z% \1 f8 v- W) ]6 x - $filter = ["matches.events_id"=>['$lt'=>'8'];3 v8 c2 Y( R8 ~' J
. d2 G- D* {; ?4 L s2 v- 0 w2 `% P+ W' N
- 以上条件说明 http://bbs.cncml.com/forum.php?m ... &extra=page%3D1
0 {1 W6 F. e8 Q# E% k
. @8 E: i- w+ n1 B+ l4 a6 a- $options = [
/ P. q2 T: ]/ j2 F - 'projection' => ['_id' => 0,"s_lastid" => 1],
+ i! S. f$ x+ O - 'limit' => 1, //显示条数" s" W6 y0 J1 g# G
- 'skip' => 1 //跳过几条! \& J$ {: f+ v
- ]; B$ K- ]0 H( P0 u7 a
% ?- w0 u) H8 {1 ~$ T3 z- $querys = new MongoDB\Driver\Query($filter,$options);$ s, W( V' `: u2 H
- $cursors = $manager->executeQuery('football.football_Competition_season_matches', $querys);
/ _" g' a$ o7 r9 j - $schedule= mg_querys($cursors);- V( X" i; W l. ^& t# o5 b) D
- print_r($schedule);$ c9 h6 I% _) ~
复制代码 ) M5 ~% H& h; L+ p7 c
9 h! I ]4 g1 K6 v, {# J
# K" Q. W1 L9 ?: @, z- }8 u0 J) p6 G6 g5 H$ m W9 R7 J
------------------------------------------------------------------------------------- 一、更新前通过控制台查看数据,查看命令如下 db.sites.find().pretty() 二、通过php实现数据更新,代码如下 <?php // 1.创建数据库连接对象 $manager = new MongoDB\Driver\Manager("mongodb://localhost:27017");
; T/ e% D* }! {4 J3 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] );
4 W8 {7 r& h* E% A! n// 3.创建更新操作级别对象 // 说明:MongoDB\Driver\WriteConcern::MAJORITY :抛出网络错误异常、服务器错误异常;并等待一个主服务器完成写操作 // 1000:等待超时时间 $writeConcern = new MongoDB\Driver\WriteConcern(MongoDB\Driver\WriteConcern::MAJORITY, 1000);
! c* e( |4 ~" k6 X// 4.执行写命令 // 说明:test.sites是test库下的sites集合 // $bulk:更新对象 // $writeConcern:写操作保证级别 $result = $manager->executeBulkWrite('test.sites', $bulk, $writeConcern); 2 `0 i7 d2 D E
// 5.输出更新后的结果 var_dump($result); 代码截图如下: 运行结果截图如下: 三、通过控制台查看更新后的数据,查看命令如下 db.sites.find().pretty() ! q% M. S- @+ q. ^5 e+ S
7 e. I0 \* U$ q/ Q! J. K* b |