I
I
Ivan Sushkov2017-01-27 16:01:45
PHP
Ivan Sushkov, 2017-01-27 16:01:45

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();

PS There is an idea that a manager is being created and through it there is a call to the example database. But how this syntax is handled is not clear. The documentation does not explain much about this point, as well as how you can open a stream using MongoDB\Driver\Manager. Apparently this is obvious enough.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Igor Deyashkin, 2017-02-02
@jamesgoodwin

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");

Well, now we get the MongoDB\GridFS\Bucket object to work with the file storage in the $database.
Perhaps I somehow misunderstood what your problem is - so ask additional. questions in the comments

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question