0

I have been following the docs on how to update a trip using Node.js,mongoose,express, as well as a couple of stack overflow questions here and here.

Inside of my Controller I originally had a save, which was working, but I needed to switch it to an update. When I run the code, nothing breaks and the place is properly logged to the console as I would expect, which further indicates that the code is being run, but for some reason it isn't overwriting the item that has the same placeIdentifier.

What am I doing wrong that prevents this from updating?

My controller:

var place = {
    identifier: placeIdentifier,
    name: placeName,
    location: Location,
    travelStart: startDate,
    travelEnd: endDate,
}

Place.findOneAndUpdate(
    {identifier:placeIdentifier}, 
    { $set: place }, 
    {upsert: true},
    function() {
        console.log(place)
        console.log("place saved...")
    }   
);
Community
  • 1
  • 1
maudulus
  • 10,627
  • 10
  • 78
  • 117

1 Answers1

0

Oh, I got it. Or rather, this person got it: Mongoose: Find, modify, save

User.findOne({username: oldUsername}, function (err, user) {
    user.username = newUser.username;
    user.password = newUser.password;
    user.rights = newUser.rights;

    user.save(function (err) {
        if(err) {
            console.error('ERROR!');
        }
    });
});
Community
  • 1
  • 1
maudulus
  • 10,627
  • 10
  • 78
  • 117