barrycumbie / ubiquitous-umbrella-dev

barry's fall 2024 dev thingy: https://ubiquitous-umbrella-dev.onrender.com/
https://barrycumbie.github.io/ubiquitous-umbrella-dev/
GNU General Public License v3.0
4 stars 24 forks source link

update #35

Closed barrycumbie closed 1 month ago

barrycumbie commented 1 month ago

app.post('/updateDrink/:id', async (req, res) => {

try { console.log("req.parms.id: ", req.params.id)

client.connect; 
const collection = client.db("chillAppz").collection("drinkz");
let result = await collection.findOneAndUpdate( 
  {"_id": ObjectId(req.params.id)}, { $set: {"size": "REALLY BIG DRINK" } }
)
.then(result => {
  console.log(result); 
  res.redirect('/');
})
barrycumbie commented 1 month ago
<h3> Current Drinkz on hand</h3> 
 <% for (var i=0; i< drinkData.length; i++ ) { %>
  <form method="POST" action="/updateDrink/<%= drinkData[i]._id %>" style="display: inline-block">  
    <%= drinkData[i].drink_name %> (<%= drinkData[i].size %>) 
    <input type="submit" value="update"> 
  </form>
  <br/>
<% } %>
barrycumbie commented 1 month ago

Needed the new keyword:

let result = await collection.findOneAndUpdate( 
  {"_id": new ObjectId(req.params.id)}, { $set: {"post": "NEW POST" } }
barrycumbie commented 1 month ago

here's the video!

https://youtu.be/5WgB2bySQys