Monday, January 2, 2023

Menggunakan Query Like MongoDB Pada PHP

 


Berikut adalah query mysql untuk like:

select * from namatabel where namakolom LIKE '%katakunci%' order by kolomsort DESC LIMIT 0, 10;


Untuk digunakan di mongoDB php :

<?php

$dbName = 'namadb';

$tableName = 'namacollection';

$kolom = 'kolomygdicari';

$keyword = 'katakunci';

$sortby = 'kolomsort';

$limit = 10;

$skip = 0;

$returns = array();

$manager = new MongoDB\Driver\Manager();

$filter = array($kolom=> new MongoDB\BSON\Regex($keyword, 'i'));

$options = array('limit'=>$limit,'skip'=>$skip,'sort'=>array($sortby=>-1));

$query = new MongoDB\Driver\Query($filter, $options);

$cursor = $manager->executeQuery($dbName.'.'.$tableName, $query);

$cursor->setTypeMap(['root' => 'array', 'document' => 'array', 'array' => 'array']);

$cursor = $cursor->toArray();

foreach ($cursor as $document) {

    $document['_id'] = (array) $document['_id'];

    $returns[] = $document;

}

echo '<pre>';

print_r($returns);

echo '</pre>';

echo '<hr />';


Memunculkan Simbol & Emoji Pada OS Mac

  Memunculkan Simbol & Emoji  1. Buka aplikasi Pages / Notes pada Macbook. 2. Klik pada Menubar Edit --> Pilih Emoji and Symbols a...