I am trying to save bunch of tags into the db and want to get the id in return but I keep on getting the [ Promise { <pending> } ]
const tagsArray = tags.split(',');
const tagIds = await tagsArray.map(async name => {
return await Tags.findOneAndUpdate({
name
}, {
$addToSet: { user }
}, {
new: true,
upsert: true
}).then(result => {
return result;
})
});
when I try to console.log(tagIds)
I only get [ Promise { <pending> } ]
I used to write without the .then()
but still doesn't work though.
How can I get the result?
Thanks in advance for any help.