Reputation: 1420
I have a NodeJS Express APP and I am building an endpoint to update Terms&Conditions
http://127.0.0.1:3000/api/admin/info/terms/de?version=2
However the text I'm trying to store is way too heavy (text has tabs, single and double quotes and so on), and requires a ton of editing in order to be placed in a json body {"terms":"easy text"}. {"terms": "heavy "text//"" that . "I dont" wish to""" editööäääÄÄ""}
What's the best way of handling this kind of text? Convert it to binary and then send it?
My endpoint
router.post('/terms/:language', async (req, res) => {
try {
const { language } = req.params;
const { version } = req.query;
const { terms } = req.body;
if (!version) return res.status(400).json({ message: 'Field "version" is empty' });
let info = await PageInfo.findOne({ $and: [{ version }, { language }] });
if (info) {
const update = await PageInfo.findOneAndUpdate({ version: { $eq: version } }, {
$set: {
version,
terms,
language
}
}, { new: true });
return res.status(200).json({ type: 'update', data: update });
}
info = await PageInfo.create({
version,
terms,
language,
});
return res.status(200).json({ type: 'new', data: info });
} catch (e) {
return res.sendStatus(500);
}
});
Upvotes: 0
Views: 93
Reputation: 613
It looks like GridFS is what you will want to use.
You can read more about it here: GridFS
If this doesn't solve your issue, based on my experience, these kinds of issues arise when your schema is poorly modeled so you may want to reconsider how you model it.
Upvotes: 1