https://github.com/atiksoftware/php-class-db-mongodb
PHP MongoDB database class
https://github.com/atiksoftware/php-class-db-mongodb
Last synced: 11 months ago
JSON representation
PHP MongoDB database class
- Host: GitHub
- URL: https://github.com/atiksoftware/php-class-db-mongodb
- Owner: atiksoftware
- Created: 2018-09-04T21:02:38.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2019-04-08T21:34:43.000Z (about 7 years ago)
- Last Synced: 2025-07-01T05:39:40.074Z (12 months ago)
- Language: PHP
- Size: 9.77 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# PHP MongoDB database class
This is php class for connect to mogodb with php. Its working on PHP.5 mongo and PHP.7 mongodb
----------
## Installation
### Using Composer
```sh
composer require atiksoftware/php-class-db-mongodb
```
```php
require __DIR__.'/../vendor/autoload.php';
use Atiksoftware\Database\MongoDB;
$db = new MongoDB();
```
#### _connect to server_
```php
$db->connect("mongodb://127.0.0.1:27017", "username","password");
```
#### _connect to Database_
```php
$db->setDatebase("public_swain_test");
```
#### _connect to Collection_
```php
$db->setCollection("posts");
```
#### _Select_
```php
$db
->orderBy(["_id" => 1])
->projectBy(["title.TR" => 1])
->limit(1)
->skip(1)
->select();
```
#### _Insert_
```php
$db->insert([ "_id" => "ucak-0", "name" => "F-".time() ]);
$db->insert([
[ "_id" => "ucak-1", "name" => "F-".time() ],
[ "_id" => "ucak-2", "name" => "F-".time() ],
[ "_id" => "ucak-3", "name" => "F-".time() ],
],true);
```
#### _Update_
```php
$db->when(["_id" => "ucak-1"])->update(["name" => "F-".time()],true);
$db->when(["_id" => "ucak-2"])->update(["name" => "F-".time()],true);
$db->when(["_id" => "ucak-3"])->update(["name" => "F-".time()],true);
$db->when(["_id" => "ucak-4"])->update(["name" => "F-".time()],true);
```
#### _Remove_
```php
$db->when(["age" => ['$gt' => 20]])->remove();
```