即日起在codingBlog上分享您的技术经验即可获得积分,积分可兑换现金哦。

The MongoDB\Driver\Manage class 翻译

编程语言 YQXLLWY 44℃ 0评论
本文目录
[隐藏]

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

1.The MongoDB\Driver\Manage class

(mongodb >=1.0.0)

1.1.简介

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结构中是很重要的。


2.MongoDB\Driver\Manager::executeBulkWrite

(mongodb>=1.0.0)

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

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

2.1.说明

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

2.2.参数

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。

2.3.返回值

Returns MongoDB\Driver\WriteResult on success.

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

3.MongoDB\Driver\Manager::executeCommand

(mongodb >=1.0.0)


MongoDB\Driver\Manager::executeCommand — Execute a database command

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

3.1.说明

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,如果不设置,则采用默认的显示习惯。

3.2.参数

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实例对象。

3.3.返回值

Returns MongoDB\Driver\Cursor on success.

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

4.MongoDB\Driver\Manager::executeQuery

(mongodb >=1.0.0)


MongoDB\Driver\Manager::executeQuery — Execute a database query

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

4.1.说明

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设置的话,则采用,否则采用默认值。

4.2.参数

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.

4.3.返回值

Returns MongoDB\Driver\Cursor on success.

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

5.MongoDB\Driver\Manager::getReadConcern

(mongodb >=1.1.0)


MongoDB\Driver\Manager::getReadConcern — Return the ReadConcern for the Manager

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

5.1.说明

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设置。

5.2.参数

此函数没有参数

5.3.返回值

The MongoDB\Driver\ReadConcern for the Manager.

MongoDB的MongoDB\Driver\ReadConcern。

6.MongoDB\Driver\Manager::getReadPreference

7.MongoDB\Driver\Manager::getServers

8.MongoDB\Driver\getWriteConcern

9.MongoDB\Driver\selectServer

转载请注明:CodingBlog » The MongoDB\Driver\Manage class 翻译

喜欢 (0)or分享 (0)
发表我的评论
取消评论

*

表情