user3163275 user3163275 - 9 months ago 65
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';


Use mongodump and mongorestoreBack Up and Restore with MongoDB Tools