Docs Menu
Docs Home
/ /

MongoDB PHP Library

Welcome to the documentation site for the official MongoDB PHP Library. The PHP library provides a high-level abstraction around the lower-level mongodb extension.

The mongodb extension provides a limited API to connect to a MongoDB database and execute generic commands, queries, and write operations. In contrast, the PHP library provides a full-featured API and models client, database, and collection objects. If you are developing a PHP application with MongoDB, consider using the PHP library instead of the extension alone.

This section describes how the components of the PHP driver work together. These components fit into the following general categories:

  • High-Level API, which includes the library and other integrations

  • Extension, which includes the extension that integrates the system libraries

  • System, which includes the C Driver, BSON library, and encryption library

The following diagram illustrates the architecture of the PHP driver components:

PHP driver component architecture

The PHP library provides an API that is consistent with the other MongoDB drivers. The library is continually updated to meet cross-driver specifications. You must add the library as a dependency to access MongoDB in most PHP applications.

The extension is distributed by using PECL, and connects PHP to the system libraries. The extension's public API provides the following functionality:

  • Connection management

  • BSON encoding and decoding

  • Object document serialization

  • Command execution

  • Cursor management

To learn more about the system libraries, see the C Driver documentation.

Learn how to install the library and extension, establish a connection to MongoDB, and begin working with data in the Get Started with the MongoDB PHP Library tutorial.

Learn how to create and configure a connection to a MongoDB deployment in the Connect to MongoDB section.

Learn how to use the PHP library to work with MongoDB databases and collections in the Databases and Collections section.

Learn how to find, update, and delete data in the CRUD Operations section.

Learn how to use the PHP library to perform aggregation operations in the Aggregation Operations section.

Learn how to work with specialized data formats and custom types in the Data Formats section.

Learn how to work with common types of indexes in the Indexes for Query Optimization section.

Learn how to run a database command in the Run a Database Command section.

Learn how to run Atlas Search queries in the Run an Atlas Search Query section.

Learn how to run Atlas Vector Search queries in the Run an Atlas Vector Search Query section.

Learn how to monitor changes to your application and write them to logs in the Logging and Monitoring section.

Learn about ways you can authenticate your application and encrypt your data in the Secure Your Data section.

Learn more about PHP library versions, compatibility, and upgrade considerations in the Reference section.

Learn how to report bugs, contribute to the library, and find help in the Issues & Help section.

Next

Getting Started

On this page