Skip to content

Instantly share code, notes, and snippets.

@ThomasSquall
Last active January 5, 2018 17:21
Show Gist options
  • Save ThomasSquall/82b4ae7a09c2cdf4d61e19a6e22405ce to your computer and use it in GitHub Desktop.
Save ThomasSquall/82b4ae7a09c2cdf4d61e19a6e22405ce to your computer and use it in GitHub Desktop.
<?php
include_once "vendor/autoload.php";
include_once "src/Adapter.php";
include_once "src/Configs.php";
use MongoDriver\Adapter;
use MongoDriver\Configs;
/**
* [\MongoDriver\Models\Model(name = "cars")]
*/
class Car
{
/**
* [\MongoDriver\Models\Fields\Required]
* @var string $name
*/
public $name;
/**
* [\MongoDriver\Models\Fields\Ref(model = "Owner", field = "name")]
* @var string $owner
*/
public $owner;
}
/**
* [\MongoDriver\Models\Model(name = "owners")]
*/
class Owner
{
/**
* [\MongoDriver\Models\Fields\Required]
* @var string $name
*/
public $name;
}
Configs::registerModel("testDB", new Car());
Configs::registerModel("testDB", new Owner());
$adapter = new Adapter();
$adapter->connect("mongodb://localhost:27017");
$adapter->selectDB("testDB");
$find = $adapter->findOne("cars")->populate('owner');
print_r($find);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment