utopia-php / mongo
A simple library to manage Mongo database
Installs: 97 576
Dependents: 2
Suggesters: 0
Security: 0
Stars: 5
Watchers: 6
Forks: 1
Open Issues: 0
Requires
- php: >=8.0
- ext-mongodb: *
- mongodb/mongodb: 1.10.0
Requires (Dev)
- fakerphp/faker: ^1.14
- laravel/pint: 1.2.*
- phpstan/phpstan: 1.8.*
- phpunit/phpunit: ^9.4
- swoole/ide-helper: 4.8.0
- dev-main
- 0.3.1
- 0.3.0
- 0.2.0
- 0.1.0
- 0.0.2
- 0.0.1
- dev-feat-github-action
- dev-bump-mongo-version
- dev-feat-insert-many
- dev-feat-authless
- dev-feat-multi-update
- dev-remove_adapters
- dev-error.2
- dev-feat-add-adapter-pattern
- dev-fix-recursive-object
- dev-fix-driver-gen-objectid
- dev-dev
- dev-revert-2-shmuel.1
- dev-shmuel.1
This package is auto-updated.
Last update: 2024-11-21 08:01:51 UTC
README
A non-blocking PHP client based on the line protocol for MongoDB. Designed to work well in async PHP environments like Swoole This library is aiming to be as simple and easy to learn and use. This library is maintained by the Appwrite team.
Getting Started
Install using composer:
composer require utopia-php/mongo
Init in your application:
<?php $client = new Client('testing', 'mongo', 27017, 'root', 'example', false); $client->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