cpride11 / ubiquitous-umbrella-dev

Courtney's Fall 2024 CIS 486 Projects
https://cpride11.github.io/ubiquitous-umbrella-dev.onrender.com
GNU General Public License v3.0
0 stars 0 forks source link

Update #25

Open cpride11 opened 4 hours ago

cpride11 commented 4 hours 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('/');
})
cpride11 commented 4 hours 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/>
<% } %>
cpride11 commented 4 hours ago

Needed the new keyword:

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

here's the video!

https://youtu.be/5WgB2bySQys