Download the PHP package phpdot/mongodb without Composer

On this page you can find all versions of the php package phpdot/mongodb. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package mongodb

phpdot/mongodb

Resilient MongoDB client for PHP 8.3+. Fluent CRUD builders, typed Document object, auto-reconnect, exception translation, and query logging. Wraps mongodb/mongodb v2.x.


Table of Contents


Install

Requirement Version
PHP >= 8.3
ext-mongodb >= 2.1
mongodb/mongodb >= 2.1

Quick Start


Architecture

Package structure:


MongoConnection

MongoConfig

Immutable readonly DTO. All 17 parameters have sensible defaults.

Multiple hosts:

With authentication:

MongoConnection Lifecycle

Topologies

Resilience

Every collection operation runs through runWithReconnect:

  1. Execute the operation
  2. On ConnectionException or connection error code: reconnect with exponential backoff (100ms, 200ms, 400ms...), refresh the collection reference, retry once
  3. On other errors: translate to typed exception

Recognized connection error codes: HostUnreachable (6), HostNotFound (7), NetworkTimeout (89), SocketException (9001), NotWritablePrimary (10107), InterruptedAtShutdown (11600), InterruptedDueToReplStateChange (11602), NotPrimaryNoSecondaryOk (13435), NotPrimaryOrSecondary (13436).


Database

Collection Access

Transactions

Transactions require a replica set. The callback receives the Database and a Session.

If the callback throws, the transaction is automatically aborted and the exception re-thrown.

Database Commands

Collection Management


Collection

Insert

Find (Quick Access)

Find (Fluent Builder)

find() returns a FindQuery with 16 chainable methods. Call execute(), first(), or count() to run.

Update (Fluent Builder)

updateOne() and updateMany() return an UpdateQuery.

Delete (Fluent Builder)

deleteOne() and deleteMany() return a DeleteQuery.

Replace

Replace the entire document (not a partial update).

Atomic Find-and-Modify

Find a document and atomically modify it. Returns the document before modification (by default).

Bulk Write

Execute multiple write operations in a single command.

Count and Distinct

Aggregation

PHPdot delegates aggregation building to mongodb/mongodb's Pipeline builder (46 stages, 37 accumulators, 190 expressions). PHPdot wraps execution with resilience and Document wrapping.

Index Management

Explain

Analyze query execution plans.

Change Streams

Watch for real-time changes on a collection (requires replica set).


Document

Every document returned from queries is a Document instance. Immutable, with automatic BSON-to-PHP type conversion on access.

Field Access

Type Conversions

Automatic on __get() access:

BSON Type PHP Type Notes
UTCDateTime DateTimeImmutable UTC timezone
Nested document (associative array) Document Recursive — $doc->address->city
Array (list) PHP array Native foreach, count
Int64 int Native arithmetic
Binary string Via getData()
ObjectId ObjectId (unchanged) Has __toString
Decimal128 Decimal128 (unchanged) Has __toString
string, int, float, bool, null unchanged PHP natives

toArray() converts everything to plain PHP (ObjectId and Decimal128 become strings).

Conversion Methods

ArrayAccess and JsonSerializable


Cursor

Cursor wraps MongoDB's cursor and yields Document instances. Implements IteratorAggregate.


Filter Builder

Build MongoDB query filters with a fluent API. All methods return self for chaining.

Use with builders via where():

Comparison Operators

Array Operators

Logical Operators

Element Operators

String Operators

Geospatial Operators

Raw Filters


Query Logging

Ring buffer logger with slow query tracking. Shared across all collections via Database.

Logged operations: findOne, find, insertOne, insertMany, updateOne, updateMany, deleteOne, deleteMany, replaceOne, countDocuments, estimatedDocumentCount, distinct, findOneAndUpdate, findOneAndReplace, findOneAndDelete, bulkWrite, aggregate.


GridFS

Store and retrieve large files. Wraps MongoDB's GridFS with a clean API.


Exception Handling

Exception Hierarchy

All exceptions carry the original MongoDB driver exception as getPrevious().

Exception Translation

MongoDB Error PHPdot Exception Error Code
Duplicate key violation DuplicateKeyException 11000, 11001
Document validation failure ValidationException 121
Execution timeout TimeoutException 50
MongoConnection lost after retry ConnectionException 6, 7, 89, 9001, ...
Authentication failure AuthenticationException varies
Other write errors WriteException varies
Other read errors QueryException varies
Bulk write failure BulkWriteException varies

Catching Exceptions


Escape Hatches

Every wrapper exposes the underlying mongodb/mongodb object for edge cases:


API Reference

MongoConfig API

MongoConnection API

Database API

Collection API

FindQuery API

UpdateQuery API

DeleteQuery API

Document API

Cursor API

Filter API

QueryLogger API

Bucket API

Exceptions API


License

MIT


All versions of mongodb with dependencies

PHP Build Version
Package Version
Requires php Version >=8.3
ext-mongodb Version ^2.1
mongodb/mongodb Version ^2.1
phpdot/contracts Version ^1.4
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package phpdot/mongodb contains the following files

Loading the files please wait ...