Search code examples
phpbulkinsertmongodbbson

Bulk Insert (like import) bson encoded data in mongodb


I am new to mongodb and thinking of trying this out in PHP5. If someone has any info or has done this please help. Basically I have a an object (or array of arrays) in PHP that I bson_encode. I am not sure how mongo db works but it seems to support batch insert. So I was wondering how would I like [LOAD DATA...] in mongodb using the bson_encoded collection of documents. thank you

Update: ok seems like batch insert only allows array (or any insert) Maybe I misunderstood that mongodb can query in bson (including inserts). so this is what I am trying now. bson_decode and batchInsert.


Solution

  • Any reason you're not using the batch insert built into the PHP driver?

    https://www.php.net/manual/en/mongocollection.batchinsert.php