PHP code example of atiksoftware / php-class-db-mongodb

1. Go to this page and download the library: Download atiksoftware/php-class-db-mongodb library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

atiksoftware / php-class-db-mongodb example snippets




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

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

$db->setDatebase("public_swain_test");

$db->setCollection("posts");

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

$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);

$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);

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