'Save/get data to/from server-side using mangodb instead of local drive
I want to use Mongodb server to get/save data receiving from another server. Currently it is done by using following method. The modelid is the parameters which is called in .json format from local folder "progressCache". The same .json file to be stored again using POST method. I would like to use Mongodb server instead of local folder.
Disclaimer:I dont have any knowledge of Mongodb.
router.get('/getProgress', async (req, res, next) => {
try {
if(req.query.ModelId === null){
res.status(400).end("Invalid model id!");
}
else{
let path = 'progressCache/' + req.query.ModelId + '.json';
if(fs.existsSync(path)){
let rawdata = fs.readFileSync(path);
res.status(200).end(JSON.stringify(JSON.parse(rawdata)));
}
else{
res.status(400).end();
}
}
} catch(err) {
next(err);
}
});
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
