This example shows a simple insert:
$collection = (new MongoDB\Client)->example->users;
$insertOneResult = $collection->insertOne([
'username' => 'admin',
'email' => 'admin@example.com',
'name' => 'Admin User',
]);
printf("Inserted %d document(s)
", $insertOneResult->getInsertedCount());
var_dump($insertOneResult->getInsertedId());
... but using the latest PHP driver, I get an error if I have a .
in the collection name (collection.attribute
), for example:
$collection = (new MongoDB\Client)->collection.attribute->users;