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.
I am using mongodb and node express.
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)
}
})
})
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.
- How to store all the data in bulk to the backend?
- I have few references between the schema, so will new '_id' be created hence affecting my references
- If you think this is not the right way to export the data, how can it be done using node express?