I am getting this error SyntaxError: Unexpected string in JSON at position 80
at JSON.parse (<anonymous>)
const User = require('../models/user')
const App = require('../models/app')
exports.add_app_to_collection = (req, res) => {
let application = {}
App.find({_id: req.body.appId}, (err, app) => {
application = app
})
User.update({
"_id": req.body.userID,
"collections.collName": req.body.collID
},
{
$push: {"collections.$.collApps": application
}})
.then(result => {
res.status(200).json({
message: "the app is added to collection"
})
})
}
Both User
and App
are mongoose models. I expect the problem is inside the first parameter of the update function but I do not know how to solve it. I tried to not to use double quotes for _id
and collections.collName
but it still does not work.
Note: I used this answer if you want to know what I am doing. Mongodb $push in nested array