MongoDB PHP驱动

1、MongoDB驱动列表

https://www.mongodb.com/docs/drivers/

Mongodb的php驱动有两个扩展,名称分别为
mongo (https://pecl.php.net/package/mongo) (已停止更新和维护,只支持PHP5)
mongodb (https://pecl.php.net/package/mongodb) (支持新版本PHP和Mongodb)\

1.1、mongo扩展的API

•核心类
  •MongoClient — MongoClient 类
  •MongoDB — MongoDB 类
  •MongoCollection — The MongoCollection class
  •MongoCursor — The MongoCursor class

•Types
  •MongoId — MongoId 类
  •MongoCode — The MongoCode class
  •MongoDate — The MongoDate class
  •MongoRegex — MongoRegex 类
  •MongoBinData — The MongoBinData class
  •MongoInt32 — MongoInt32 类
  •MongoInt64 — MongoInt64 类
  •MongoDBRef — MongoDBRef 类
  •MongoMinKey — The MongoMinKey class
  •MongoMaxKey — The MongoMaxKey class
  •MongoTimestamp — MongoTimestamp 类

•GridFS Classes
  •MongoGridFS — The MongoGridFS class
  •MongoGridFSFile — The MongoGridFSFile class
  •MongoGridFSCursor — The MongoGridFSCursor class

•Miscellaneous
  •MongoLog — The MongoLog class
  •MongoPool — The MongoPool class
  •Mongo — The Mongo class [deprecated]

•Mongo 函数
  •bson_decode — 反序列化一个 BSON 对象为 PHP 数组
  •bson_encode — 序列化一个 PHP 变量为 BSON 字符串

•Exceptions
  •MongoException — The MongoException class
  •MongoResultException — MongoResultException 类
  •MongoCursorException — The MongoCursorException class
  •MongoCursorTimeoutException — The MongoCursorTimeoutException class
  •MongoConnectionException — The MongoConnectionException class
  •MongoGridFSException — The MongoGridFSException class
  •MongoDuplicateKeyException — The MongoDuplicateKeyException class
  •MongoProtocolException — The MongoProtocolException class
  •MongoExecutionTimeoutException — The MongoExecutionTimeoutException class
  •MongoWriteConcernException — The MongoWriteConcernException class

1.2、mongodb扩展的API

•MongoDB\Driver — MongoDB 驱动类
  •MongoDB\Driver\Manager — The MongoDB\Driver\Manager class
  •MongoDB\Driver\Command — The MongoDB\Driver\Command class
  •MongoDB\Driver\Query — The MongoDB\Driver\Query class
  •MongoDB\Driver\BulkWrite — The MongoDB\Driver\BulkWrite class
  •MongoDB\Driver\WriteConcern — The MongoDB\Driver\WriteConcern class
  •MongoDB\Driver\ReadPreference — The MongoDB\Driver\ReadPreference class
  •MongoDB\Driver\ReadConcern — The MongoDB\Driver\ReadConcern class
  •MongoDB\Driver\Cursor — The MongoDB\Driver\Cursor class
  •MongoDB\Driver\CursorId — The MongoDB\Driver\CursorId class
  •MongoDB\Driver\Server — The MongoDB\Driver\Server class
  •MongoDB\Driver\WriteConcernError — The MongoDB\Driver\WriteConcernError class
  •MongoDB\Driver\WriteError — The MongoDB\Driver\WriteError class
  •MongoDB\Driver\WriteResult — The MongoDB\Driver\WriteResult class

•MongoDB\BSON — BSON type classes and serialization functions
  •函数
  •MongoDB\BSON\Binary — The MongoDB\BSON\Binary class
  •MongoDB\BSON\Decimal128 — The MongoDB\BSON\Decimal128 class
  •MongoDB\BSON\Javascript — The MongoDB\BSON\Javascript class
  •MongoDB\BSON\MaxKey — The MongoDB\BSON\MaxKey class
  •MongoDB\BSON\MinKey — The MongoDB\BSON\MinKey class
  •MongoDB\BSON\ObjectId — The MongoDB\BSON\ObjectId class
  •MongoDB\BSON\Regex — The MongoDB\BSON\Regex class
  •MongoDB\BSON\Timestamp — The MongoDB\BSON\Timestamp class
  •MongoDB\BSON\UTCDateTime — The MongoDB\BSON\UTCDateTime class
  •MongoDB\BSON\Type — The MongoDB\BSON\Type interface
  •MongoDB\BSON\Persistable — The MongoDB\BSON\Persistable interface
  •MongoDB\BSON\Serializable — The MongoDB\BSON\Serializable interface
  •MongoDB\BSON\Unserializable — The MongoDB\BSON\Unserializable interface
  •MongoDB\BSON\BinaryInterface — The MongoDB\BSON\BinaryInterface interface
  •MongoDB\BSON\Decimal128Interface — The MongoDB\BSON\Decimal128Interface interface
  •MongoDB\BSON\JavascriptInterface — The MongoDB\BSON\JavascriptInterface interface
  •MongoDB\BSON\MaxKeyInterface — The MongoDB\BSON\MaxKeyInterface interface
  •MongoDB\BSON\MinKeyInterface — The MongoDB\BSON\MinKeyInterface interface
  •MongoDB\BSON\ObjectIdInterface — The MongoDB\BSON\ObjectIdInterface interface
  •MongoDB\BSON\RegexInterface — The MongoDB\BSON\RegexInterface interface
  •MongoDB\BSON\TimestampInterface — The MongoDB\BSON\TimestampInterface interface
  •MongoDB\BSON\UTCDateTimeInterface — The MongoDB\BSON\UTCDateTimeInterface interface
  •MongoDB\BSON\DBPointer — The MongoDB\BSON\DBPointer class (deprecated)
  •MongoDB\BSON\Int64 — The MongoDB\BSON\Int64 class
  •MongoDB\BSON\Symbol — The MongoDB\BSON\Symbol class (deprecated)
  •MongoDB\BSON\Undefined — The MongoDB\BSON\Undefined class (deprecated)

•MongoDB\Driver\Monitoring — Monitoring classes and subscriber functions
  •函数
  •MongoDB\Driver\Monitoring\CommandFailedEvent — The MongoDB\Driver\Monitoring\CommandFailedEvent class
  •MongoDB\Driver\Monitoring\CommandStartedEvent — The MongoDB\Driver\Monitoring\CommandStartedEvent class
  •MongoDB\Driver\Monitoring\CommandSucceededEvent — The MongoDB\Driver\Monitoring\CommandSucceededEvent class
  •MongoDB\Driver\Monitoring\CommandSubscriber — The MongoDB\Driver\Monitoring\CommandSubscriber interface
  •MongoDB\Driver\Monitoring\Subscriber — The MongoDB\Driver\Monitoring\Subscriber interface

•MongoDB\Driver\Exception — Exception 类
  •MongoDB\Driver\Exception\AuthenticationException — The MongoDB\Driver\Exception\AuthenticationException class
  •MongoDB\Driver\Exception\BulkWriteException — The MongoDB\Driver\Exception\BulkWriteException class
  •MongoDB\Driver\Exception\ConnectionException — The MongoDB\Driver\Exception\ConnectionException class
  •MongoDB\Driver\Exception\ConnectionTimeoutException — The MongoDB\Driver\Exception\ConnectionTimeoutException class
  •MongoDB\Driver\Exception\Exception — The MongoDB\Driver\Exception\Exception interface
  •MongoDB\Driver\Exception\ExecutionTimeoutException — The MongoDB\Driver\Exception\ExecutionTimeoutException class
  •MongoDB\Driver\Exception\InvalidArgumentException — The MongoDB\Driver\Exception\InvalidArgumentException class
  •MongoDB\Driver\Exception\LogicException — The MongoDB\Driver\Exception\LogicException class
  •MongoDB\Driver\Exception\RuntimeException — The MongoDB\Driver\Exception\RuntimeException class
  •MongoDB\Driver\Exception\SSLConnectionException — The MongoDB\Driver\Exception\SSLConnectionException class (deprecated)
  •MongoDB\Driver\Exception\UnexpectedValueException — The MongoDB\Driver\Exception\UnexpectedValueException class
  •MongoDB\Driver\Exception\WriteException — The MongoDB\Driver\Exception\WriteException class

参考:https://www.php.net/manual/zh/set.mongodb.php

2、Mongodb驱动介绍

参考官方文档
Mongodb的php驱动是包含两个组件:

- PHP扩展-mongodb ([https://www.php.net/mongodb](https://www.php.net/mongodb)):提供低级API,主要用于将libmongoc和libbson与PHP集成。  
- PHP库 [https://www.mongodb.com/docs/php-library/current/](https://www.mongodb.com/docs/php-library/current/):提供高级API,并且与其他MongoDB语言驱动一致。

PHP扩展提供了一个有限的API来连接数据库和执行通用命令、查询和写操作。
PHP库提供了一个功能齐全的API和模型客户端、数据库和集合对象。例如,MongoDB\Collection实现了在集合上执行CRUD操作和管理索引的方法。PHP库的API与MongoDB shell(https://blog.csdn.net/penngo/article/details/124232016)的API操作相似.

2.1、MongoDB版本的兼容性

PHP Driver Versions
MongoDB 5.3
MongoDB 5.2
MongoDB 5.1
MongoDB 5.0
MongoDB 4.4
MongoDB 4.2
MongoDB 4.0
MongoDB 3.6
MongoDB 3.4
MongoDB 3.2
MongoDB 3.0
MongoDB 2.6
ext 1.13 + lib 1.12
ext 1.12 + lib 1.11
ext 1.11 + lib 1.10
ext 1.10 + lib 1.9
ext 1.9 + lib 1.8
ext 1.8 + lib 1.7
ext 1.7 + lib 1.6
ext 1.6 + lib 1.5
ext 1.5 + lib 1.4
ext 1.4 + lib 1.3
ext 1.3 + lib 1.2
ext 1.2 + lib 1.1
ext 1.1 + lib 1.0
ext 1.0

2.2、PHP版本的兼容性

PHP Driver Versions
PHP 8.1
PHP 8.0
PHP 7.4
PHP 7.3
PHP 7.2
PHP 7.1
PHP 7.0
PHP 5.6
PHP 5.5
ext 1.13 + lib 1.12

ext 1.12 + lib 1.11

ext 1.11 + lib 1.10

ext 1.10 + lib 1.9

ext 1.9 + lib 1.8

ext 1.8 + lib 1.7

ext 1.7 + lib 1.6

ext 1.6 + lib 1.5

ext 1.5 + lib 1.4

ext 1.4 + lib 1.3

ext 1.3 + lib 1.2

3、安装驱动

使用MongoDB的PHP库前,需要先安装PHP扩展。

3.1、安装mongodb扩展

Linux、Unix和macOS用户可以使用PECL安装扩展(推荐),也可以手动从源代码编译扩展。 下面的命令可以用于使用PECL安装扩展:

sudo pecl install mongodb

安装完扩展,需要在php.ini文件中添加:

extension=mongodb.so

Windows用户可以从PECL(https://pecl.php.net/package/mongodb)下载预编译的二进制文件,将php_mongodb.dll文件解压缩到PHP的扩展目录后,在PHP.ini文件中添加以下行:

extension=php_mongodb.dll

3.2、MongoDB驱动mongodb扩展CRUD操作

连接 MongoDB 语法如下:

<?php

$manager = new MongoDB\Driver\Manager('mongodb://localhost:27017');
var_dump($manager);

?> 

参考:https://www.php.net/manual/zh/class.mongodb-driver-manager.php

3.2.1、插入、修改、删除操作,使用MongoDB\Driver\BulkWrite
<?php

$bulk = new MongoDB\Driver\BulkWrite(['ordered' => true]);
$bulk->delete([]);
$bulk->insert(['_id' => 1, 'x' => 1,'url'=>'https://21doc.net/']);
$bulk->insert(['_id' => 2, 'x' => 2,'url'=>'https://21doc.net/']);
$bulk->update(
    ['x' => 2],
    ['$set' => ['x' => 1]],
    ['limit' => 1, 'upsert' => false]
);
$bulk->delete(['x' => 1], ['limit' => 1]);
$bulk->update(
    ['_id' => 3],
    ['$set' => ['x' => 3]],
    ['limit' => 1, 'upsert' => true]
);

$manager = new MongoDB\Driver\Manager('mongodb://localhost:27017');
$writeConcern = new MongoDB\Driver\WriteConcern(1);

try {
    $result = $manager->executeBulkWrite('db.collection', $bulk, $writeConcern);
} catch (MongoDB\Driver\Exception\BulkWriteException $e) {
    $result = $e->getWriteResult();

    // Check if the write concern could not be fulfilled
    if ($writeConcernError = $result->getWriteConcernError()) {
        printf("%s (%d): %s\n",
            $writeConcernError->getMessage(),
            $writeConcernError->getCode(),
            var_export($writeConcernError->getInfo(), true)
        );
    }

    // Check if any write operations did not complete at all
    foreach ($result->getWriteErrors() as $writeError) {
        printf("Operation#%d: %s (%d)\n",
            $writeError->getIndex(),
            $writeError->getMessage(),
            $writeError->getCode()
        );
    }
} catch (MongoDB\Driver\Exception\Exception $e) {
    printf("Other error: %s\n", $e->getMessage());
    exit;
}

printf("Inserted %d document(s)\n", $result->getInsertedCount());
printf("Updated  %d document(s)\n", $result->getModifiedCount());
printf("Upserted %d document(s)\n", $result->getUpsertedCount());
printf("Deleted  %d document(s)\n", $result->getDeletedCount());

?>

参考:https://www.php.net/manual/zh/class.mongodb-driver-bulkwrite.php

3.2.2、查询操作
<?php
/* Select only documents authord by "bjori" with at least 100 views */
$filter = [
    'author' => 'bjori',
    'views' => [
        '$gte' => 100,
    ],
];

$options = [
    /* Only return the following fields in the matching documents */
    'projection' => [
        'title' => 1,
        'article' => 1,
    ],
    /* Return the documents in descending order of views */
    'sort' => [
        'views' => -1
    ],
];

$query = new MongoDB\Driver\Query($filter, $options);

$manager = new MongoDB\Driver\Manager('mongodb://localhost:27017');
$readPreference = new MongoDB\Driver\ReadPreference(MongoDB\Driver\ReadPreference::RP_PRIMARY);
$cursor = $manager->executeQuery('databaseName.collectionName', $query, $readPreference);

foreach($cursor as $document) {
    var_dump($document);
}

?>

参考:https://www.php.net/manual/zh/mongodb-driver-query.construct.php

3.3、安装MongoDB PHP库

推荐使用Composer安装,在项目根目录下运行命令:

composer require mongodb/mongodb    # 下载最新版本
composer require mongodb/mongodb^1.12.0 # 下载指定1.12.0版本

也可以从GitHub中下载mongo-php-library下载源码,但是不建议。

自动加载
需要项目中包含Composer的自动加载器。

<?php

require_once __DIR__ . '/vendor/autoload.php';

3.4、MongoDB PHP库CRUD操作,参考

3.4.1、插入一个文档

MongoDB\Collection::insertOne()方法将单个文档插入到MongoDB中,并返回一个MongoDB\InsertOneResult的实例,可以使用它来访问插入的文档的ID。

<?php

$collection = (new MongoDB\Client)->test->users;

$insertOneResult = $collection->insertOne([
    'username' => 'admin',
    'email' => 'admin@example.com',
    'name' => 'Admin User',
    'url'=>'https://21doc.net/'
]);

printf("Inserted %d document(s)\n", $insertOneResult->getInsertedCount());

var_dump($insertOneResult->getInsertedId());
3.4.2、插入多个文档

MongoDB\Collection::insertMany() 方法允许您在一个写操作中插入多个文档,并返回一个 MongoDB\InsertManyResult实例,可以使用它来访问插入文档的id。

<?php

$collection = (new MongoDB\Client)->test->users;

$insertManyResult = $collection->insertMany([
    [
        'username' => 'admin',
        'email' => 'admin@example.com',
        'name' => 'Admin User',
        'url'=>'https://21doc.net/'
    ],
    [
        'username' => 'test',
        'email' => 'test@example.com',
        'name' => 'Test User',
        'url'=>'https://21doc.net/'
    ],
]);

printf("Inserted %d document(s)\n", $insertManyResult->getInsertedCount());

var_dump($insertManyResult->getInsertedIds());
3.4.3、查询文档

MongoDB PHP库提供了MongoDB\Collection::findOne()和MongoDB\Collection::find()方法用于查询文档,以及MongoDB\Collection::aggregate()方法用于执行聚合操作。

3.4.3.1、查询一个文档
<?php

$collection = (new MongoDB\Client)->test->zips;

$document = $collection->findOne(['_id' => '94301']);

var_dump($document);

参考:MongoDB\Collection::findOne()

3.4.3.2、查询多个文档
<?php

$collection = (new MongoDB\Client)->test->restaurants;

$cursor = $collection->find(
    [
        'cuisine' => 'Italian',
        'borough' => 'Manhattan',
    ],
    [
        'projection' => [
            'name' => 1,
            'borough' => 1,
            'cuisine' => 1,
        ],
        'limit' => 4,
    ]
);

foreach($cursor as $restaurant) {
   var_dump($restaurant);
};

参考:MongoDB\Collection::find()

3.4.3.3、正则查询
<?php

$collection = (new MongoDB\Client)->test->zips;

$cursor = $collection->find([
    'city' => new MongoDB\BSON\Regex('^garden', 'i'),
    'state' => 'TX',
]);

foreach ($cursor as $document) {
   printf("%s: %s, %s\n", $document['_id'], $document['city'], $document['state']);
}

参考:https://www.mongodb.com/docs/manual/reference/operator/query/regex/

3.4.3.4、聚合查询
<?php

$collection = (new MongoDB\Client)->test->zips;

$cursor = $collection->aggregate([
    ['$group' => ['_id' => '$state', 'count' => ['$sum' => 1]]],
    ['$sort' => ['count' => -1]],
    ['$limit' => 5],
]);

foreach ($cursor as $state) {
    printf("%s has %d zip codes\n", $state['_id'], $state['count']);
}

参考:MongoDB\Collection::aggregate()

3.4.4、更新文档
3.4.4.1、更新一个文档

使用MongoDB\Collection::updateOne()方法更新匹配过滤器的单个文档。 MongoDB\Collection::updateOne()返回一个MongoDB\UpdateResult对象,可以使用它来访问关于更新操作的统计信息。

<?php

$collection = (new MongoDB\Client)->test->users;
$collection->drop();

$collection->insertOne(['name' => 'Bob', 'state' => 'ny']);
$collection->insertOne(['name' => 'Alice', 'state' => 'ny']);
$updateResult = $collection->updateOne(
    ['state' => 'ny'],
    ['$set' => ['country' => 'us']]
);

printf("Matched %d document(s)\n", $updateResult->getMatchedCount());
printf("Modified %d document(s)\n", $updateResult->getModifiedCount());

参考
MongoDB\Collection::updateOne()
MongoDB\Collection::findOneAndUpdate()

3.4.4.2、更新多个文档

MongoDB\Collection::updateMany()更新一个或多个匹配过滤条件的文档,并返回一个MongoDB\UpdateResult对象,可以使用它来访问关于更新操作的统计信息。

<?php

$collection = (new MongoDB\Client)->test->users;
$collection->drop();

$collection->insertOne(['name' => 'Bob', 'state' => 'ny', 'country' => 'us']);
$collection->insertOne(['name' => 'Alice', 'state' => 'ny']);
$collection->insertOne(['name' => 'Sam', 'state' => 'ny']);
$updateResult = $collection->updateMany(
    ['state' => 'ny'],
    ['$set' => ['country' => 'us']]
);

printf("Matched %d document(s)\n", $updateResult->getMatchedCount());
printf("Modified %d document(s)\n", $updateResult->getModifiedCount());

参考:MongoDB\Collection::updateMany()

3.4.4.3、替换文档

MongoDB\Collection::replaceOne()方法替换匹配过滤条件的单个文档,并返回一个MongoDB\UpdateResult实例,可以使用它来访问关于替换操作的统计信息。

<?php

$collection = (new MongoDB\Client)->test->users;
$collection->drop();

$collection->insertOne(['name' => 'Bob', 'state' => 'ny']);
$updateResult = $collection->replaceOne(
    ['name' => 'Bob'],
    ['name' => 'Robert', 'state' => 'ca']
);

printf("Matched %d document(s)\n", $updateResult->getMatchedCount());
printf("Modified %d document(s)\n", $updateResult->getModifiedCount());

参考:
MongoDB\Collection::replaceOne()
MongoDB\Collection::findOneAndReplace()

3.4.5、删除文档
3.4.5.1、删除一个文档

MongoDB\Collection::deleteOne()方法删除一个匹配过滤条件的文档,并返回一个MongoDB\DeleteResult,可以使用它来访问关于删除操作的统计信息。 The MongoDB\Collection::deleteOne() method deletes a single document that matches the filter criteria and returns a MongoDB\DeleteResult, which you can use to access statistics about the delete operation.

<?php

$collection = (new MongoDB\Client)->test->users;
$collection->drop();

$collection->insertOne(['name' => 'Bob', 'state' => 'ny']);
$collection->insertOne(['name' => 'Alice', 'state' => 'ny']);
$deleteResult = $collection->deleteOne(['state' => 'ny']);

printf("Deleted %d document(s)\n", $deleteResult->getDeletedCount());
3.4.5.2、删除多个文档

MongoDB\Collection::deleteMany()删除所有符合过滤条件的文档,并返回一个MongoDB\DeleteResult,可以使用它来访问关于删除操作的统计信息。

<?php

$collection = (new MongoDB\Client)->test->users;
$collection->drop();

$collection->insertOne(['name' => 'Bob', 'state' => 'ny']);
$collection->insertOne(['name' => 'Alice', 'state' => 'ny']);
$deleteResult = $collection->deleteMany(['state' => 'ny']);

printf("Deleted %d document(s)\n", $deleteResult->getDeletedCount());

参考:MongoDB\Collection::deleteMany()

4、php库API

BSON
MongoDB\Client Class
    MongoDB\Client::__construct()
    MongoDB\Client::__get()
    MongoDB\Client::createClientEncryption()
    MongoDB\Client::dropDatabase()
    MongoDB\Client::getManager()
    MongoDB\Client::getReadConcern()
    MongoDB\Client::getReadPreference()
    MongoDB\Client::getTypeMap()
    MongoDB\Client::getWriteConcern()
    MongoDB\Client::listDatabaseNames()
    MongoDB\Client::listDatabases()
    MongoDB\Client::selectCollection()
    MongoDB\Client::selectDatabase()
    MongoDB\Client::startSession()
    MongoDB\Client::watch()
MongoDB\Database Class
    MongoDB\Database::__construct()
    MongoDB\Database::__get()
    MongoDB\Database::aggregate()
    MongoDB\Database::command()
    MongoDB\Database::createCollection()
    MongoDB\Database::drop()
    MongoDB\Database::dropCollection()
    MongoDB\Database::getDatabaseName()
    MongoDB\Database::getManager()
    MongoDB\Database::getReadConcern()
    MongoDB\Database::getReadPreference()
    MongoDB\Database::getTypeMap()
    MongoDB\Database::getWriteConcern()
    MongoDB\Database::listCollectionNames()
    MongoDB\Database::listCollections()
    MongoDB\Database::modifyCollection()
    MongoDB\Database::renameCollection()
    MongoDB\Database::selectCollection()
    MongoDB\Database::selectGridFSBucket()
    MongoDB\Database::watch()
    MongoDB\Database::withOptions()
MongoDB\Collection Class
    MongoDB\Collection::__construct()
    MongoDB\Collection::aggregate()
    MongoDB\Collection::bulkWrite()
    MongoDB\Collection::count()
    MongoDB\Collection::countDocuments()
    MongoDB\Collection::createIndex()
    MongoDB\Collection::createIndexes()
    MongoDB\Collection::deleteMany()
    MongoDB\Collection::deleteOne()
    MongoDB\Collection::distinct()
    MongoDB\Collection::drop()
    MongoDB\Collection::dropIndex()
    MongoDB\Collection::dropIndexes()
    MongoDB\Collection::estimatedDocumentCount()
    MongoDB\Collection::explain()
    MongoDB\Collection::find()
    MongoDB\Collection::findOne()
    MongoDB\Collection::findOneAndDelete()
    MongoDB\Collection::findOneAndReplace()
    MongoDB\Collection::findOneAndUpdate()
    MongoDB\Collection::getCollectionName()
    MongoDB\Collection::getDatabaseName()
    MongoDB\Collection::getManager()
    MongoDB\Collection::getNamespace()
    MongoDB\Collection::getReadConcern()
    MongoDB\Collection::getReadPreference()
    MongoDB\Collection::getTypeMap()
    MongoDB\Collection::getWriteConcern()
    MongoDB\Collection::insertMany()
    MongoDB\Collection::insertOne()
    MongoDB\Collection::listIndexes()
    MongoDB\Collection::mapReduce()
    MongoDB\Collection::rename()
    MongoDB\Collection::replaceOne()
    MongoDB\Collection::updateMany()
    MongoDB\Collection::updateOne()
    MongoDB\Collection::watch()
    MongoDB\Collection::withOptions()
MongoDB\GridFS\Bucket Class
    MongoDB\GridFS\Bucket::__construct()
    MongoDB\GridFS\Bucket::delete()
    MongoDB\GridFS\Bucket::downloadToStream()
    MongoDB\GridFS\Bucket::downloadToStreamByName()
    MongoDB\GridFS\Bucket::drop()
    MongoDB\GridFS\Bucket::find()
    MongoDB\GridFS\Bucket::findOne()
    MongoDB\GridFS\Bucket::getBucketName()
    MongoDB\GridFS\Bucket::getChunksCollection()
    MongoDB\GridFS\Bucket::getChunkSizeBytes()
    MongoDB\GridFS\Bucket::getDatabaseName()
    MongoDB\GridFS\Bucket::getFileDocumentForStream()
    MongoDB\GridFS\Bucket::getFileIdForStream()
    MongoDB\GridFS\Bucket::getFilesCollection()
    MongoDB\GridFS\Bucket::getReadConcern()
    MongoDB\GridFS\Bucket::getReadPreference()
    MongoDB\GridFS\Bucket::getTypeMap()
    MongoDB\GridFSBucket::getWriteConcern()
    MongoDB\GridFS\Bucket::openDownloadStream()
    MongoDB\GridFS\Bucket::openDownloadStreamByName()
    MongoDB\GridFS\Bucket::openUploadStream()
    MongoDB\GridFS\Bucket::rename()
    MongoDB\GridFS\Bucket::uploadFromStream()
Write Result Classes
    MongoDB\BulkWriteResult::getDeletedCount()
    MongoDB\BulkWriteResult::getInsertedCount()
    MongoDB\BulkWriteResult::getInsertedIds()
    MongoDB\BulkWriteResult::getMatchedCount()
    MongoDB\BulkWriteResult::getModifiedCount()
    MongoDB\BulkWriteResult::getUpsertedCount()
    MongoDB\BulkWriteResult::getUpsertedIds()
    MongoDB\BulkWriteResult::isAcknowledged()
    MongoDB\DeleteResult::getDeletedCount()
    MongoDB\DeleteResult::isAcknowledged()
    MongoDB\InsertManyResult::getInsertedCount()
    MongoDB\InsertManyResult::getInsertedIds()
    MongoDB\InsertManyResult::isAcknowledged()
    MongoDB\InsertOneResult::getInsertedCount()
    MongoDB\InsertOneResult::getInsertedId()
    MongoDB\InsertOneResult::isAcknowledged()
    MongoDB\UpdateResult::getMatchedCount()
    MongoDB\UpdateResult::getModifiedCount()
    MongoDB\UpdateResult::getUpsertedCount()
    MongoDB\UpdateResult::getUpsertedId()
    MongoDB\UpdateResult::isAcknowledged()
Result Classes
    MongoDB\ChangeStream::current()
    MongoDB\ChangeStream::getCursorId()
    MongoDB\ChangeStream::getResumeToken()
    MongoDB\ChangeStream::key()
    MongoDB\ChangeStream::next()
    MongoDB\ChangeStream::rewind()
    MongoDB\ChangeStream::valid()
    MongoDB\MapReduceResult::getCounts()
    MongoDB\MapReduceResult::getExecutionTimeMS()
    MongoDB\MapReduceResult::getIterator()
    MongoDB\MapReduceResult::getTiming()
Enumeration Classes
    MongoDB\Model\CollectionInfo::getCappedMax()
    MongoDB\Model\CollectionInfo::getCappedSize()
    MongoDB\Model\CollectionInfo::getIdIndex()
    MongoDB\Model\CollectionInfo::getInfo()
    MongoDB\Model\CollectionInfo::getName()
    MongoDB\Model\CollectionInfo::getOptions()
    MongoDB\Model\CollectionInfo::getType()
    MongoDB\Model\CollectionInfo::isCapped()
    MongoDB\Model\DatabaseInfo::getName()
    MongoDB\Model\DatabaseInfo::getSizeOnDisk()
    MongoDB\Model\DatabaseInfo::isEmpty()
    MongoDB\Model\IndexInfo::getKey()
    MongoDB\Model\IndexInfo::getName()
    MongoDB\Model\IndexInfo::getNamespace()
    MongoDB\Model\IndexInfo::getVersion()
    MongoDB\Model\IndexInfo::is2dSphere()
    MongoDB\Model\IndexInfo::isGeoHaystack()
    MongoDB\Model\IndexInfo::isSparse()
    MongoDB\Model\IndexInfo::isText()
    MongoDB\Model\IndexInfo::isTtl()
    MongoDB\Model\IndexInfo::isUnique()
Functions
    MongoDB\with_transaction()
Exception Classes

参考https://www.mongodb.com/docs/php-library/current/reference/

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

penngo

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值