Answer the question
In order to leave comments, you need to log in
MongoDB GridFS PHP - how to read an example?
The official MongoDB GridFS documentation says that in order to successfully work with GridFS, a developer can use MongoDB\Driver\Manager or the MongoDB PHP Library class MongoDB\Database (more precisely, its selectGridFSBucket() method ). My question is about an example of how this works. Please help me understand what is happening in the following line:
$bucket = (new MongoDB\Client)->example->selectGridFSBucket();
Answer the question
In order to leave comments, you need to log in
The command can be divided into parts to make it easier to understand.
We get the connection object to the database (MongoDB\Client)
We get the MongoDB\Database object for working with a specific database. The __get magic method is used here , the documentation says:
That is, the following commands do the same thing.
$database = $connection->example;
$database = $connection->selectDatabase("example");
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question