PHPackages                             alexanderthegreat96/mongo-api-client - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. alexanderthegreat96/mongo-api-client

ActiveLibrary

alexanderthegreat96/mongo-api-client
====================================

Provides a fluid interface with MongoDB API

v1.1.2(11mo ago)020MITPHP

Since May 25Pushed 11mo ago1 watchersCompare

[ Source](https://github.com/alexanderthegreat96/mongo-api-php-client)[ Packagist](https://packagist.org/packages/alexanderthegreat96/mongo-api-client)[ RSS](/packages/alexanderthegreat96-mongo-api-client/feed)WikiDiscussions origin Synced 1mo ago

READMEChangelog (7)Dependencies (2)Versions (14)Used By (0)

MongoDB API Client (PHP)
========================

[](#mongodb-api-client-php)

A PHP client library for interacting with a MongoDB RESTful API, providing a fluent interface for building queries and performing CRUD operations with robust response handling.

Overview
--------

[](#overview)

The `MongoApiClient` class enables seamless interaction with a MongoDB API server, supporting operations like selecting, inserting, updating, and deleting documents. Key features include:

- **Fluent Query Building**: Chain methods like `where`, `orWhere`, `sortBy`, `groupBy` for complex queries.
- **Query Aliases**: Use `all` (preferred), `select`, `get` for `find()`, and `first` (preferred), `firstOrNone`, `one` for `first()`.
- **Auto-Conversion Control**: Toggle type conversion for query values using `autoConvert` in `where`/`orWhere`.
- **Grouped Data Handling**: Process grouped query results with `MongoApiResponseData`, including inner pagination and records.
- **Pagination Support**: Handle pagination metadata via `MongoApiResponsePagination`.
- **Retry Mechanism**: Automatically retry failed requests with configurable exponential backoff.
- **Response Wrapping**: Normalize API responses into a consistent `MongoApiResponse` envelope.
- **Iterator and Countable Data**: `MongoApiResponseData` supports iteration and counting for flexible data handling.

Installation
------------

[](#installation)

Install the package using Composer:

```
composer require alexanderthegreat96/mongo-api-client
```

Ensure PHP 8.1+ and the `guzzlehttp/guzzle` library are installed (included as a dependency).

Configuration
-------------

[](#configuration)

Configure the client using constructor parameters or environment variables for sensitive data like API keys. Supported environment variables:

- `MONGO_API_URL`: API server URL (e.g., `api.example.com`).
- `MONGO_API_PORT`: Server port (default: `80`).
- `MONGO_API_KEY`: API key for authentication Cage for MongoDB API Client.
- `MONGO_API_SCHEME`: Protocol (`http` or `https`, default: `https`).
- `MONGO_API_TIMEOUT`: Request timeout in seconds (default: `5.0`).

Example using environment variables:

```
