The MongoDB\Driver\Manage class 翻译

12 篇文章 0 订阅

PHP官网中The MongoDB\Driver\Manage class的翻译。

The MongoDB\Driver\Manage class

(mongodb >=1.0.0)

简介

The MongoDB\Driver\Manager is the main entry point to the extension. It is responsible for maintaining connections to MongoDB (be it standalone server, replica set, or sharded cluster).

No connection to MongoDB is made upon instantiating the Manager. This means the MongoDB\Driver\Manager can always be constructed, even though one or more MongoDB servers are down.

Any write or query can throw connection exceptions as connections are created lazily. A MongoDB server may also become unavailable during the life time of the script. It is therefore important that all actions on the Manager to be wrapped in try/catch statements.

MongoDB\Driver\Manage是该类扩展的主入口。他主要的作用是连接MongoDB(该类支持独立数据库、复制集或者分片)。

如果要连接MongoDB,一定要实例化Manage类,而且一个实例化的对象可以支持同时连接多台服务器。

当连接没有建立的时候,任何读写操作都会抛出链接错误的异常。当脚本运行期间,MongoDB服务器可能会不可达。所以把所有操作包含在try/catch结构中是很重要的。


MongoDB\Driver\Manager::executeBulkWrite

(mongodb>=1.0.0)

MongoDB\Driver\Manage::executeBulkWrite-Execute one or more write operations

MongoDB\Driver\Manage::executeBulkWrite-执行一条或者多条写操作。

说明

Executes one or more write operations on the primary server.

A MongoDB\Driver\BulkWrite can be constructed with one or more write operations of varying types (e.g. updates, deletes, and inserts). The driver will attempt to send operations of the same type to the server in as few requests as possible to optimize round trips.

在当前服务器上执行一次或者多次写操作。

一个MongoDB\Driver\BulkWrite实例可以执行多种多种写操作(像更新、删除、增加)。该驱动会尝试将相同类型的操作一次性全部发送给服务器,从而减少请求次数。

参数

namespace (string)
A fully qualified namespace (e.g. “databaseName.collectionName”).

数据库名称.集合名称组成的字符串。

bulk (MongoDB\Driver\BulkWrite)
The MongoDB\Driver\BulkWrite to execute.

MongoDB\Driver\BulkWrite对象

writeConcern (MongoDB\Driver\WriteConcern)
Optionally, a MongoDB\Driver\WriteConcern to apply to the write operation. If none is given, the write concern from the MongoDB Connection URI will be used.

writeConcern(MongoDB\Driver\WriteConcern)
一个随意的对应本次写操作的MongoDB\Driver\WriteConcern实例。如果没有设置该值,默认是本次连接中的URI。

返回值

Returns MongoDB\Driver\WriteResult on success.

成功的话,返回一个MongoDB\Driver\WriteResult实例。

MongoDB\Driver\Manager::executeCommand

(mongodb >=1.0.0)
MongoDB\Driver\Manager::executeCommand — Execute a database command

MongoDB\Driver\Manage::executeCommand 执行命令行命令

说明

Executes command on a server If readPreference is provided, it will be used for server selection; otherwise, the default read preference will be used.

在服务器上执行MongoDB命令,可以设置readPreference,如果不设置,则采用默认的显示习惯。

参数

db (string)
The name of the database on which to execute the command.

执行该命令的数据库名称。

command (MongoDB\Driver\Command)
The MongoDB\Driver\Command to execute.

MongoDB\Driver\Command实例对象

readPreference (MongoDB\Driver\ReadPreference)
Optionally, a MongoDB\Driver\ReadPreference to select the server for this operation. If none is given, the read preference from the MongoDB Connection URI will be used.

一个MongoDB\Driver\ReadPreference实例对象。

返回值

Returns MongoDB\Driver\Cursor on success.

成功的话返回一个MongoDB\Driver\Cursor对象实例。

MongoDB\Driver\Manager::executeQuery

(mongodb >=1.0.0)
MongoDB\Driver\Manager::executeQuery — Execute a database query

MongoDB\Driver\Manage::executeQuery 执行数据库查询

说明

Executes query on a server. If readPreference is provided, it will be used for server selection; otherwise, the default read preference will be used.

在服务器上执行一次查询。如果readPreference设置的话,则采用,否则采用默认值。

参数

namespace (string)
A fully qualified namespace (e.g. “databaseName.collectionName”).

格式:”数据库名称.表名称”

query (MongoDB\Driver\Query)
The MongoDB\Driver\Query to execute.

一个MongoDB\Driver\Query对象实例。

readPreference (MongoDB\Driver\ReadPreference)
Optionally, a MongoDB\Driver\ReadPreference to select the server for this operation. If none is given, the read preference from the MongoDB Connection URI will be used.

返回值

Returns MongoDB\Driver\Cursor on success.

一个MongoDB\Driver\Cursor的对象实例。

MongoDB\Driver\Manager::getReadConcern

(mongodb >=1.1.0)
MongoDB\Driver\Manager::getReadConcern — Return the ReadConcern for the Manager

MongoDB\Driver\Manage::getReadConcern 返回当前Manager连接的ReadConcern对象实例。

说明

Returns the MongoDB\Driver\ReadConcern for the Manager, which is derived from its URI options. This is the default read concern for queries and commands executed on the Manager.

返回当前Manage连接的MongoDB\Driver\ReadConcern对象实例,该实例是URI操作衍生出来的。这是Manager进行查询和执行命令时的默认ReadConcern设置。

参数

此函数没有参数

返回值

The MongoDB\Driver\ReadConcern for the Manager.

MongoDB的MongoDB\Driver\ReadConcern。

MongoDB\Driver\Manager::getReadPreference

MongoDB\Driver\Manager::getServers

MongoDB\Driver\getWriteConcern

MongoDB\Driver\selectServer

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值