PHP 7.4.19 Released!

Getting A Collection

Getting a collection has the same syntax as getting a database:

= new MongoClient();
$db $connection->baz;

// select a collection:
$collection $db->foobar;

// or, directly selecting a database and collection:
$collection $connection->baz->foobar;

A collection is analogous to a table (if you are familiar with relational databases).

See Also

The API documentation on the MongoCollection class contains more information about collection objects.

add a note add a note

User Contributed Notes 1 note

jerome at chaman dot ca
6 years ago
If your collection uses dot notation, get it with MongoDB::selectCollection :

$colors = $db->selectCollection('my.colors');
To Top