https://github.com/utopia-php/mongo
https://github.com/utopia-php/mongo
hacktoberfest php utopia
Last synced: 7 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/utopia-php/mongo
- Owner: utopia-php
- Created: 2022-09-14T08:00:57.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2025-07-10T09:49:23.000Z (7 months ago)
- Last Synced: 2025-07-10T17:48:59.541Z (7 months ago)
- Topics: hacktoberfest, php, utopia
- Language: PHP
- Homepage:
- Size: 105 KB
- Stars: 5
- Watchers: 6
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Non-Blocking PHP Line Protocol Client for MongoDB
[](https://travis-ci.com/utopia-php/mongo)

[](https://appwrite.io/discord)
A non-blocking PHP client based on the line protocol for MongoDB. Designed to work well in async PHP environments like [Swoole](https://github.com/swoole/swoole-src)
This library is aiming to be as simple and easy to learn and use.
This library is maintained by the [Appwrite team](https://appwrite.io).
## Getting Started
Install using composer:
```bash
composer require utopia-php/mongo
```
Init in your application:
```php
connect();
// drop database
$client->dropDatabase([]);
// Create a new collection
$client->createCollection('movies');
// Get the list of databases
$client->listDatabaseNames()->databases;
// insert a new document
$document = $client->insert('movies', [
'name' => 'Armageddon 1',
'country' => 'USA',
'language' => 'English'
]
);
$id = (string)$document['_id'];
// Find Document with ObjectId
$client->find('movies', ['_id' => new ObjectId($id)])->cursor->firstBatch ?? [];
// insert a new document with specific id
$id = 999;
$client->insert('movies', [
'name' => 'Armageddon 2',
'_id' => $id,
'array' => ['USA', 'UK', 'India'],
'language' => 'English',
'float' => 9.9,
'integer' => 9,
'is_open' => true,
'date_string' => (new \DateTime())->format('Y-m-d\TH:i:s.vP'),
]
);
// Find document by id
$client->find('movies', ['_id' => $id])->cursor->firstBatch ?? [];
// Find documents by field
$client->find('movies', ['name' => 'Armageddon'])->cursor->firstBatch ?? [];
// Delete a document
$client->delete('movies', ['_id' => $id]);
// drop a collections
$client->dropCollection('movies');
```
## System Requirements
Utopia Mongo client requires PHP 8.0 or later. We recommend using the latest PHP version whenever possible.
## Copyright and license
The MIT License (MIT) [http://www.opensource.org/licenses/mit-license.php](http://www.opensource.org/licenses/mit-license.php)