I am facing an issue where I need to save a user's array to mongo. When the data passes through the bridge and reaches the posts, it appears as a strange object with string versions of its indices. I am attempting to convert it back into a normal array so that it can be saved to mongo database. However, the process is very delicate and keeps throwing errors. Is there a specific parsing operation that I might be overlooking?
bridge:
static storeUsers(users){
try{
let command = 'storeUsers';
return axios.post(url + command, {
params: users
});
} catch(err){
reject(err);
}
}
posts:
router.post('/storeUsers', async (req, res) => {
let collection = await loadCollection('users');
let userArray = req.body.params.toArray(); // this line causes issues
await collection.insertMany(
userArray
);
res.status(201).send();
});