Mongo

Bson to mongodb

It's very simple to import a .bson file:
mongorestore -d db_name -c collection_name /path/file.bson

Incase only for a single collection.Try this:
mongorestore --drop -d db_name -c collection_name /path/file.bson

For restoring the complete folder exported by mongodump:
mongorestore -d db_name /path/


Node Backup Mongo


  const backupMongo = function () {
    const fileName = 'archive' + moment().format('YYYY-MM-DD-hh:mm') + '.gz'
    spawn = require("child_process").spawn;
    let backupProcess = spawn("mongodump", [
      "--host=52.9.218.54",
      "--port=27017",
      "--username=mohotdb",
      "--password=mohot12345",
      "--db=mohot",
      "--archive=" + fileName,
      "--gzip",
    ]);

    backupProcess.on("exit", (code, signal) => {
      if (code) console.log("Backup process exited with code ", code);
      else if (signal)
        console.error("Backup process was killed with singal ", signal);
      else console.log("Successfully backedup the database");
    });
  };