In order to create new documents, you can use any of the following methods:
-
- MongoDB\Collection::insertOne()
- MongoDB\Collection::insertMany()
- MongoDB\Collection::bulkWrite()
Obviously, the last two are convenient when you want to insert multiple documents in one operation. The main downside to the last two methods, as defined in PHPLIB, is that you need to provide an array of documents. This takes up memory and might not be appropriate when a massive amount of data needs to be inserted.
In this example, however, the CSV file only contains 82 entries, and thus insertMany() is used:
// initialize env require __DIR__ . '/vendor/autoload.php'; use Application\ {Client, Csv}; // set up mongodb client + collection $params ...