Answer the question
In order to leave comments, you need to log in
.save() method not working?
The problem is, there is a code
router.post('/add-file-to-play-list', async (req, res) => {
const user = await User.findById({_id: req.body.userId})
const music = await Music.findById({_id: req.body.audioId})
const indexPlayList = await getIndexEl(user.playLists, 'name', req.body.namePlayList)
const indexMainPlayList = await getIndexEl(music.files, 'name', req.body.nameAudio)
const playList = user.playLists[indexPlayList]
if(!playList.files) {
playList.files = []
}
playList.files.push(music.files[indexMainPlayList])
await user.save()
res.send(JSON.stringify({
user
}))
})
{
"user": {
"role": 0,
"avatar": "storage/avatars/avatar.png",
"playLists": [
{
"name": "Избранные",
"files": [
{
"name": "I'm So Sick",
"path": "storage/music/flyleaf/01-i'm-so-sick.m4a",
"likes": 0,
"year": 2005
}
]
}
],
"_id": "5f68bf62e85ae5056c5854d8",
"email": "[email protected]",
"login": "user",
"password": "$2a$10$KTiyMuZnC.IYzw81VpqsN.cflWMZJA.dQXGeQhsnWJruvYRKM.00S",
"__v": 4
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question