Problem updating nested data in database

Problem updating nested data in database
0.0 0

#1

I’m currently working on the nightlife coordination app and I’ve run into a problem with the user story where a user can add themselves to a bar. When I request the data from the Yelp API, I add a property to it called attendance and save it to the database. When someone clicks the “add me” button, a request is sent to the server and the object is pulled from the database. My problem is that I can’t seem to update the attendance property. This is my model:

const listSchema = new Schema({
    list: Array,
    location: String,
    query: String,
    users: Array
});

The array returned from the API request is stored in list. In order to change the attendance property, I called forEach on the array, looking for a match with the bar name. Once a match is found I say “object.attendance++” and call markModified, but it’s still not being updated.


#2

So I tried making a more direct query with $elemMatch, but it’s still not working.

List.findOne({list: {$elemMatch: {name: req.body.data.name, query: req.body.data.query}}}, (err, busList) => {

for some reason it’s returning the entire document, and not the individual object inside the list Array. Does anyone know what the problem could be? This has been giving me trouble all day.