title: export and import data from mongodb using node.js express
body: <p>I want to export all data from my server to my local(also i don't have a backup so this will serve as a backup. So I used the below code to get the collection in a json format and save to the local.</p>
  
  <p>I am using mongodb and node express. </p>
  
  <pre><code>dbName.find().exec(function(err, output){
  
  var jsonOutput=JSON.stringify(output)
  
  fs.writeFile('downloads/output.json', output, function (err) {
          if (err) {
              console.log(err)
              res.send('error')
          }
          else{
              var filename = 'res.json'
              var mimetype = 'application/json'
  
              res.setHeader('Content-disposition', 'attachment; filename=' + filename)
              res.setHeader('Content-type', mimetype)
              res.end(jsonOutput)
          }
      })
  })
  </code></pre>
  
  <p>This gives me what I want. Now I want to process the json in my local machine so that my local data is in sync with the server.</p>
  
  <ol>
  <li>How to store all the data in bulk to the backend? </li>
  <li>I have few references between the schema, so will new '_id' be created
  hence affecting my references</li>
  <li>If you think this is not the right way to export the data, how can
      it be done using node express?</li>
  </ol>