atiksoftware/php-class-db-mongodb

PHP MongoDB database class

1.2.2 2019-04-08 21:30 UTC

This package is auto-updated.

Last update: 2024-05-09 09:09:43 UTC


README

This is php class for connect to mogodb with php. Its working on PHP.5 mongo and PHP.7 mongodb

Installation

Using Composer

composer require atiksoftware/php-class-db-mongodb
require __DIR__.'/../vendor/autoload.php';

use Atiksoftware\Database\MongoDB;
$db = new MongoDB();

connect to server

$db->connect("mongodb://127.0.0.1:27017", "username","password");

connect to Database

$db->setDatebase("public_swain_test");

connect to Collection

$db->setCollection("posts");

Select

$db
    ->orderBy(["_id" => 1])
    ->projectBy(["title.TR" => 1])
    ->limit(1)
    ->skip(1)
    ->select();

Insert

$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

$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

$db->when(["age" => ['$gt' => 20]])->remove();