Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: MongoDB persistable #185

Open
miklcct opened this issue Apr 22, 2022 · 0 comments
Open

Feature request: MongoDB persistable #185

miklcct opened this issue Apr 22, 2022 · 0 comments
Labels

Comments

@miklcct
Copy link

miklcct commented Apr 22, 2022

I would like a trait which provides methods to implement MongoDB\BSON\Persistable such that I can store enums directly into a MongoDB database and load it as is. Specifically, I hope to have an implementation of BsonTrait included in the library:

#!/usr/bin/php
<?php
declare(strict_types=1);

use MongoDB\BSON\Persistable;
use MongoDB\Client;

require_once __DIR__ . '/vendor/autoload.php';

enum Test : string implements Persistable {
    use BsonTrait;

    case FOO = 'F';
    case BAR = 'B';
}

$client = new Client(driverOptions: ['typeMap' => ['array' => 'array']]);
$database = $client->selectDatabase('test');
$collection = $database->selectCollection('test');
$collection->insertMany([Test::FOO, Test::BAR]);
var_dump($collection->find()->toArray());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants