Properties

$dbName

$dbName : 

Type

$queryStr

$queryStr : string

Type

string — 当前SQL指令

$typeMap

$typeMap : 

Type

$mongo

$mongo : 

Type

$cursor

$cursor : 

Type

$event

$event : 

Type

$links

$links : array<mixed,\think\mongo\PDO>

Type

array<mixed,\think\mongo\PDO> — 数据库连接ID 支持多个连接

$linkID

$linkID : \think\mongo\PDO

Type

\think\mongo\PDO — 当前连接ID

$linkRead

$linkRead : 

Type

$linkWrite

$linkWrite : 

Type

$numRows

$numRows : 

Type

$error

$error : 

Type

$query

$query : 

Type

$options

$options : 

Type

$config

$config : 

Type

Methods

__construct()

__construct(array  $config = array()) 

架构函数 读取数据库配置信息

Parameters

array $config

数据库配置数组

connect()

connect(array  $config = array(), integer  $linkNum) 

连接数据库方法

Parameters

array $config

连接参数

integer $linkNum

连接序号

Throws

\MongoDB\Driver\Exception\InvalidArgumentException
\MongoDB\Driver\Exception\RuntimeException

setQuery()

setQuery(\think\mongo\Query  $query,   $model = 'db') : $this

指定当前使用的查询对象

Parameters

\think\mongo\Query $query

查询对象

$model

Returns

$this

getQuery()

getQuery(string  $model = 'db', string  $queryClass = '') : \think\mongo\Query

创建指定模型的查询对象

Parameters

string $model

模型类名称

string $queryClass

查询对象类名

Returns

\think\mongo\Query

__call()

__call(string  $method, array  $args) : mixed

调用Query类的查询方法

Parameters

string $method

方法名称

array $args

调用参数

Returns

mixed

getConfig()

getConfig(string  $config = '') : mixed

获取数据库的配置参数

Parameters

string $config

配置名称

Returns

mixed

setConfig()

setConfig(string  $config, mixed  $value) : void

设置数据库的配置参数

Parameters

string $config

配置名称

mixed $value

配置值

getMongo()

getMongo() : \MongoDB\Driver\Manager|null

获取Mongo Manager对象

Returns

\MongoDB\Driver\Manager|null

db()

db(string  $db = null) 

设置/获取当前操作的database

Parameters

string $db

db

Throws

\think\Exception

query()

query(string  $namespace, \MongoDB\Driver\Query  $query, \MongoDB\Driver\ReadPreference  $readPreference = null, string|boolean  $class = false, string|array  $typeMap = null) : mixed

执行查询

Parameters

string $namespace

当前查询的collection

\MongoDB\Driver\Query $query

查询对象

\MongoDB\Driver\ReadPreference $readPreference

readPreference

string|boolean $class

返回的数据集类型

string|array $typeMap

指定返回的typeMap

Throws

\MongoDB\Driver\Exception\AuthenticationException
\MongoDB\Driver\Exception\InvalidArgumentException
\MongoDB\Driver\Exception\ConnectionException
\MongoDB\Driver\Exception\RuntimeException

Returns

mixed

command()

command(\MongoDB\Driver\Command  $command, string  $dbName = '', \MongoDB\Driver\ReadPreference  $readPreference = null, string|boolean  $class = false, string|array  $typeMap = null) : mixed

执行指令

Parameters

\MongoDB\Driver\Command $command

指令

string $dbName

当前数据库名

\MongoDB\Driver\ReadPreference $readPreference

readPreference

string|boolean $class

返回的数据集类型

string|array $typeMap

指定返回的typeMap

Throws

\MongoDB\Driver\Exception\AuthenticationException
\MongoDB\Driver\Exception\InvalidArgumentException
\MongoDB\Driver\Exception\ConnectionException
\MongoDB\Driver\Exception\RuntimeException

Returns

mixed

execute()

execute(string  $namespace, \MongoDB\Driver\BulkWrite  $bulk, \MongoDB\Driver\WriteConcern  $writeConcern = null) : \think\mongo\WriteResult

执行写操作

Parameters

string $namespace
\MongoDB\Driver\BulkWrite $bulk
\MongoDB\Driver\WriteConcern $writeConcern

Throws

\MongoDB\Driver\Exception\AuthenticationException
\MongoDB\Driver\Exception\InvalidArgumentException
\MongoDB\Driver\Exception\ConnectionException
\MongoDB\Driver\Exception\RuntimeException
\MongoDB\Driver\Exception\BulkWriteException

Returns

\think\mongo\WriteResult

log()

log(string  $type, mixed  $data, array  $options = array()) : void

数据库日志记录(仅供参考)

Parameters

string $type

类型

mixed $data

数据

array $options

参数

getQueryStr()

getQueryStr() : string

获取执行的指令

Returns

string

listen()

listen(callable  $callback) : void

监听SQL执行

Parameters

callable $callback

回调方法

free()

free() 

释放查询结果

close()

close() 

关闭数据库

replicaSetConnect()

replicaSetConnect() : \MongoDB\Driver\Manager

创建基于复制集的连接

Returns

\MongoDB\Driver\Manager

startTrans()

startTrans() : void

启动事务

Throws

\PDOException
\Exception

commit()

commit() : void

用于非自动提交状态下面的查询提交

Throws

\think\mongo\PDOException

rollback()

rollback() : void

事务回滚

Throws

\think\mongo\PDOException

__destruct()

__destruct() 

析构方法

getResult()

getResult(boolean|string  $class = '', string|array  $typeMap = null) : mixed

获得数据集

Parameters

boolean|string $class

true 返回Mongo cursor对象 字符串用于指定返回的类名

string|array $typeMap

指定返回的typeMap

Returns

mixed

trigger()

trigger(string  $sql, float  $runtime, array  $options = array()) : boolean

触发SQL事件

Parameters

string $sql

语句

float $runtime

运行时间

array $options

参数

Returns

boolean

debug()

debug(boolean  $start, string  $sql = '') : void

数据库调试 记录当前SQL及分析性能

Parameters

boolean $start

调试开始标记 true 开始 false 结束

string $sql

执行的SQL语句 留空自动获取

initConnect()

initConnect(boolean  $master = true) : void

初始化数据库连接

Parameters

boolean $master

是否主服务器

multiConnect()

multiConnect(boolean  $master = false) : \think\mongo\PDO

连接分布式服务器

Parameters

boolean $master

主服务器

Returns

\think\mongo\PDO

convertObjectID()

convertObjectID(array  $data) : void

ObjectID处理

Parameters

array $data

buildUrl()

buildUrl() : string

根据配置信息 生成适用于链接复制集的 URL

Returns

string