Download the PHP package alexanderthegreat96/mongo-api-client without Composer

On this page you can find all versions of the php package alexanderthegreat96/mongo-api-client. 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 mongo-api-client

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

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

Installation

Install the package using Composer:

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

Configuration

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

Example using environment variables:

Usage

Initializing the Client

Create a MongoApiClient instance with your API server details:

Authentication

The client uses API key authentication by default. Pass the API key in the constructor or via the MONGO_API_KEY environment variable.

Select Queries

The library provides a powerful fluent interface for select queries, with all() as the preferred method for fetching multiple documents and first() for a single document. Use getResult() to access individual document data for single or multiple results, getRecords() for grouped query results, and getCount() for counting documents.

Fetching Multiple Documents

Use all() (preferred over select() or get()) to fetch multiple documents. Iterate through the results and call getResult() on each:

The autoConvert: true ensures the age value is tagged for automatic type conversion (e.g., 18/a in the query string). The MongoApiResponseData object is countable, allowing count($data).

Fetching a Single Document

Use first() (preferred over firstOrNone() or one()) to retrieve the first matching document. Access the document with getResult():

Fetching a Document by ID

Use findById() to retrieve a document by its _id and access it with getResult():

Using orWhere with autoConvert

Combine where and orWhere for complex queries, using all() to fetch multiple documents:

Here, age is tagged for conversion (18/a), while status is not (active/n), preserving the string value.

Grouped Queries with groupBy

Group results by a field (e.g., city) and use getRecords() to access records within each group:

The MongoApiResponseData class provides:

Use innerPage and innerPerPage (or innerLimit) to control pagination within groups. The class implements IteratorAggregate for foreach loops and Countable for counting records.

Counting Documents

Use count() to get the number of matching documents. Check isOk() and call getCount():

Pagination Handling

Access pagination metadata for non-grouped or grouped queries:

For grouped queries, use getInnerPagination() on MongoApiResponseData for per-group pagination, as shown in the groupBy example.

Custom Select Queries

Execute custom MongoDB queries or aggregations, using all()-style result handling:

Use aggregate: true to execute as a pipeline query.

Other CRUD Operations

Inserting Data

Conditional Inserting

Use insertIf() to insert a document only if it matches the query conditions:

Updating Data

Updating by ID

Use updateById() to update a specific document by its _id:

Deleting Data

Deleting by ID

Use deleteById() to delete a specific document by its _id:

Utility Methods

List databases or collections:

Drop databases or collections:

Features

Error Handling

Responses are wrapped in MongoApiResponse, providing:

Common error codes:

Example handling errors:

Changelog

Version 1.2.1 (2025-05-18)

Version 1.2.0 (2025-05-18)

Version 1.1.0 (2025-05-18)

Version 1.0.0

License

This project is licensed under the MIT License. See the LICENSE file for details.


All versions of mongo-api-client with dependencies

PHP Build Version
Package Version
Requires guzzlehttp/guzzle Version ^7.8
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 alexanderthegreat96/mongo-api-client contains the following files

Loading the files please wait ....