1. Go to this page and download the library: Download phpaml/data-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/ */
phpaml / data-mongodb example snippets
use AML\Data\Entity;
use AML\Data\MongoDB\Metadata\{Collection, DocumentId};
use AML\Data\MongoDB\{MongoContext, MongoSet};
#[Collection('users')]
final class User extends Entity
{
#[DocumentId]
public string $id;
public string $name;
public int $age;
}
final class AppMongoContext extends MongoContext
{
/** @return MongoSet<User> */
public function users(): MongoSet
{
return $this->set(User::class);
}
}
$page = $db->users()
->where('age', '>=', 18)
->orderBy('name')
->paginate(page: 1, perPage: 20);
#[DocumentId(type: 'string')]
public string $id;
bash
composer test
AML_DATA_MONGODB_URI='mongodb://127.0.0.1:27017' \
AML_DATA_MONGODB_DATABASE='phpaml_data_test' \
php tests/server.php
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.