user3163275 user3163275 - 2 years ago 148
PHP Question

Mongodb php backup collections

I have a problem, my code does not work exactly as I want. I need to create a backup and restore. And that is my problem; My new collection is not identical.
Wrong data form:

My backup

$db = $m->$dbname;
$backup1 = $db->people->find();
$people = 'people.txt';
if ($text1 ){
file_put_contents($people, $text1, LOCK_EX);
echo 'complete';
else echo 'error';

My restore

$db = $m->$dbname;
$collection = $db->people1;
$file = file_get_contents('people.txt', FILE_USE_INCLUDE_PATH);
if ($file){
$file = json_decode($file);
foreach ($file as $id => $item) {
echo 'Restore complete';
else echo 'Error';

Answer Source

Use mongodump and mongorestoreBack Up and Restore with MongoDB Tools

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download