I have a collection Trips and I want to be able to add a passenger to the passenger array or create an array with a passenger. This SO answer mentions $push but even though node logs reserved seat on the trip and the front end has an alert with Your seat has been reserved the collection isn't updated (there is no passenger array in the Trips collection).
//reserve a seat for a trip
app.post('/api/trips/:trip/:passenger',function(req,res){
console.log('trip:'+req.params.trip)
console.log('passenger:'+req.params.passenger)
db.collection('Trips').update({'_id':req.params.trip},{ $push: { "passengers": req.params.passenger }},function(err,res){
if(err) throw err
console.log('reserved seat on the trip')
})
res.send('Your seat has been reserved')
})
Mongo 3.2.11
Node 9.4.0
Express 4.15.5
Is there something wrong with my MongoDB call? Am I missing a step?