Download the PHP package crazymeeks/php-mongodb without Composer
On this page you can find all versions of the php package crazymeeks/php-mongodb. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package php-mongodb
php-mongodb
#
php-mongodb is a PHP library that wraps MongoDB\Client
library and provides a clean api for interacting with MongoDB database.
#
System requirements
>=php7.2
php7.x-mongodb extension
mongodb php driver
Installation
- Install mongodb driver
apt update && apt upgrade -y
pecl install mongodb-1.9.0
- Install this library via composer
composer require crazymeeks/php-mongodb
#Usage
Connect to MongoDB Database
Extend Crazymeeks\MongoDB\Model\AbstractModel class
Inserting data
First approach:
Second approach:
Note: save()
and create()
methods will automatically add created_at
and updated_at
timestamps fields when performing an insert. If you wish to disable this, just add protected $timestamps = true;
to your model class.
Or error, this will throw \Exception
or \Error
when something went wrong.
#
Update
Single
Bulk update
Delete
Single
Bulk delete
#
Finding or Querying data from collection.
Current methods available
whereEq(string $field, string $value) - where equal query and case-insentive.
whereNotEq(string $field, string $value) - where not equal query and case-insensitive.
whereIn(string $field, array($value1, $value2, ...) - Case-insensitive.
whereNotIn(string $field, array($value1, array $value2, ...) - Case-insensitive.
whereGreater(string $field, mixed $value) $value could be int|string. Works great for int types.
whereGreaterOrEq(string $field, mixed $value) - $value could be int|string. Works great for int types.
whereLessThanOrEq(string $field, mixed $value) - $value could be int|string. Works great for int types.
whereLessThan(string $field, mixed $value) - $value could be int|string. Works great for int types.
first() - Returns object that extends \Crazymeeks\MongoDB\Model\AbstractModel. You may count()
result of this function for counter checking.
get() - Returns an array object that extends \Crazymeeks\MongoDB\Model\AbstractModel. You may count()
result of this function for counter checking.
#
Query samples
Chaining multiple queries
You may chain multiple queries too.
#
Direct Usage
In addition, you may also use all methods available in MongoDB\Client and call it directly in your model.
#
Laravel integration
Register connection to app service provider.
Model
Important: Laravel's relationship is not yet supported.
#
Author: Jeff Claud