public function __construct (
array $y_configs_arr =
[],
bool $y_fatal_err =
true
) {}
@
@throws: {Exception} Depending how this class it is constructed it may throw Exception or Raise Fatal Error
@param: {ARRAY} $y_configs_arr: *Optional* ; The Array of Configuration parameters ; Default is Empty Array, case which will get the configuration from config.php ; if custom, the ARRAY STRUCTURE should be identical with the default config.php: $configs['mongodb'].
@param: {BOOLEAN} $y_fatal_err: *Optional* ; Set if Errors handling mode ; Default is TRUE ; if set to FALSE will throw Exception instead of Raise a Fatal Error
public function escapeFtsText (
string $text
) {}
-> STRING
@return: {STRING} FTS escaped
public function escapeRegexText (
string $text
) {}
-> STRING
@return: {STRING} Regex escaped
public function __call (
) {}
@
@throws: {Exception} Depending how this class it is constructed it may throw Exception or Raise Fatal Error
Sample code: PHP
<?php
$count = $mongo->count(
'myTestCollection',
[ 'name' => [ '$eq' => 'Test:!' ] ]
);
var_dump($count);
$find = $mongo->findone(
'myTestCollection',
[ 'cost' => 7 ]
);
var_dump($find);
$mfind = $mongo->find(
'myTestCollection',
[ 'name' => 'John' ],
[
'name',
'description'
],
[
'limit' => 10,
'skip' => 0
]
);
var_dump($mfind);
$doc = [];
$doc['id'] = $mongo->assign_uuid();
$doc['name'] = 'My Name';
$doc['description'] = 'Some description goes here ...';
$insert = $mongo->insert('myTestCollection', (array)$doc);
$doc = [];
var_dump($insert);
$docs = array();
for($i=0; $i<10; $i++) {
$docs[] = [
'id' => $mongo->assign_uuid(),
'name' => 'Document #'.$i,
'cost' => ($i+1),
'data' => [
'description' => 'This is the document #'.$i,
'date_time' => (string) date('Y-m-d H:i:s'),
'rating' => Smart::random_number(1,9) / 100
]
];
}
$insert = $mongo->bulkinsert('myTestCollection', (array)$docs);
$docs = array();
var_dump($insert);
$doc = [];
$doc['name'] = 'My New Name';
$doc['description'] = 'Some description goes here ...';
$update = $mongo->update(
'myTestCollection',
[ '_id' => 'XXXXXXXXXX-XXXXXXXXXX-XXXXXXXXXX' ],
[ 0 => (array) $doc ]
);
$doc = [];
var_dump($update);
$doc = [];
$doc['name'] = 'My New Name';
$doc['description'] = 'Some description goes here ...';
$update = $mongo->update(
'myTestCollection',
[ 'id' => 'XXXXXXXXXX-XXXXXXXXXX-XXXXXXXXXX' ],
'$set',
(array) $doc
);
$doc = [];
var_dump($update);
$doc = [];
$docID = 'XXXXXXXXXX-XXXXXXXXXX-XXXXXXXXXX';
$doc['name'] = 'My Newest Name';
$doc['description'] = 'Some description goes here ...';
try {
$upsert = $mongo->upsert(
'myTestCollection',
[ 'id' => $docID ],
[
'$setOnInsert' => (array) [ 'id' => $docID ],
'$set' => (array) $doc,
'$addToSet' => (array) [ 'updated' => date('Y-m-d H:i:s') ]
]
);
} catch(Exception $err) {
}
$doc = [];
var_dump($upsert);
$delete = $mongo->delete(
'myTestCollection',
[ 'name' => 'An Item', 'cost' => 8 ]
);
var_dump($delete);
$filter = $mongo->command(
[
'distinct' => 'myTestCollection',
'key' => 'cost',
'query' => [ 'cost' => [ '$gte' => 5 ] ]
]
);
if(!$mongo->is_command_ok($filter) {
}
var_dump($filter);
public function count (
STRING $strCollection,
ARRAY $arrQuery
) {}
-> MIXED
@magic __call()
@return {MIXED}
@param {STRING} $strCollection
@param {ARRAY} $arrQuery
public function find (
STRING $strCollection,
ARRAY $arrQuery,
ARRAY $arrProjFields,
ARRAY $arrOptions
) {}
-> MIXED
@magic __call()
@return {MIXED}
@param {STRING} $strCollection
@param {ARRAY} $arrQuery
@param {ARRAY} $arrProjFields
@param {ARRAY} $arrOptions
public function findone (
STRING $strCollection,
ARRAY $arrQuery,
ARRAY $arrProjFields,
ARRAY $arrOptions
) {}
-> MIXED
@magic __call()
@return {MIXED}
@param {STRING} $strCollection
@param {ARRAY} $arrQuery
@param {ARRAY} $arrProjFields
@param {ARRAY} $arrOptions
public function bulkinsert (
STRING $strCollection,
ARRAY $arrMultiDocs
) {}
-> MIXED
@magic __call()
@return {MIXED}
@param {STRING} $strCollection
@param {ARRAY} $arrMultiDocs
public function insert (
STRING $strCollection,
ARRAY $arrDoc
) {}
-> MIXED
@magic __call()
@return {MIXED}
@param {STRING} $strCollection
@param {ARRAY} $arrDoc
public function upsert (
STRING $strCollection,
ARRAY $arrFilter,
MIXED $strUpdOpOrArrUpd,
ARRAY $arrUpd
) {}
-> MIXED
@magic __call()
@return {MIXED}
@param {STRING} $strCollection
@param {ARRAY} $arrFilter
@param {MIXED} $strUpdOpOrArrUpd
@param {ARRAY} $arrUpd
public function update (
STRING $strCollection,
ARRAY $arrFilter,
MIXED $strUpdOpOrArrUpd,
ARRAY $arrUpd
) {}
-> MIXED
@magic __call()
@return {MIXED}
@param {STRING} $strCollection
@param {ARRAY} $arrFilter
@param {MIXED} $strUpdOpOrArrUpd
@param {ARRAY} $arrUpd
public function delete (
STRING $strCollection,
ARRAY $arrFilter
) {}
-> MIXED
@magic __call()
@return {MIXED}
@param {STRING} $strCollection
@param {ARRAY} $arrFilter
public function command (
$arrCmd
) {}
-> MIXED
@magic __call()
@return {MIXED}
@param $arrCmd
public function igcommand (
$arrCmd
) {}
-> MIXED
@magic __call()
@return {MIXED}
@param $arrCmd
Tested and Stable on MongoDB Server versions: 3.2 / 3.4 / 3.6 / 4.0 / 4.1 / 4.2 / 4.3 / 4.4 / 5.0 / 5.1 / 5.2