PHP中的MongoDB驅動程序的文檔(http://php.net/manual/en/mongodb-driver-cursor.toarray.php)爲例,
示例代碼如下:如何通過PHP MongoDB驅動程序將數據從mongodb導入到mysql?
$manager = new MongoDB\Driver\Manager("mongodb://localhost:27017");
$bulk = new MongoDB\Driver\BulkWrite;
$bulk->insert(['x' => 1]);
$bulk->insert(['x' => 2]);
$bulk->insert(['x' => 3]);
$manager->executeBulkWrite('db.collection', $bulk);
$query = new MongoDB\Driver\Query([]);
$cursor = $manager->executeQuery('db.collection', $query);
var_dump($cursor->toArray());
問:
我想插入$cursor
到MySQL,我應該怎麼對它做什麼? toArray()
可以將它改成數組,但數組的元素是BSONDocument
,它們不能插入mysql。