Here's an example for all CRUD operations (Create, Read, Update, Delete) using the provided code:

Create (Insert)

app.post("/nieuwe-bezoeker", bezoekerSchema, async (req, res) => {
    // SLA BEZOEKER OP IN DB
    const postData = req.body
    const logBezoeker = await db.collection("bezoekers").insertOne(postData);
    const bericht = `Bezoeker ${postData.voornaam} ${postData.achternaam} is gelogd.`
    res.render("nieuwe-bezoeker", { bericht })
})

Read (Retrieve)

 app.get("/bezoekers", async (req, res) => {
  const query = {} // leeg laten om alle documenten op te halen
  const options = { sort: { naam: 1 } }
  // sorteer op naam oplopend (aflopend is -1)
  const gelogdeBezoekers = await db
    .collection("bezoekers")
    .find(query, options)
    .toArray(); // maak array ipv default cursor terug te geven
  res.render("bezoekers", { bezoekers: gelogdeBezoekers })
})

Update

app.put("/bezoeker/:id", async (req, res) => {
  const bezoekerId = req.params.id
  const updatedData = req.body
  await db.collection("bezoekers").updateOne({ _id: bezoekerId }, { $set: updatedData })
  res.send("Bezoeker bijgewerkt!");
})

Delete

app.delete("/bezoeker/:id", async (req, res) => {
  const bezoekerId = req.params.id;
  await db.collection("bezoekers").deleteOne({ _id: bezoekerId });
  res.send("Bezoeker verwijderd!");
});

These examples demonstrate how to perform CRUD operations using Node.js and MongoDB, assuming you have set up appropriate routes and middleware for handling requests.

In the context of MongoDB, "put", "patch", and "update" are terms commonly used in the context of CRUD (Create, Read, Update, Delete) operations, but their exact meanings can vary depending on the specific context or the technology stack being used. Here's a general overview of how these terms might be used in the context of MongoDB:

  1. PUT: In RESTful APIs, a "PUT" request typically implies a full update of a resource. In MongoDB, this would translate to replacing the entire document with a new one. When you issue a "PUT" request to update a document, you typically provide the entire updated document, and the existing document is replaced with the new one.
  2. PATCH: A "PATCH" request is used for a partial update of a resource. In MongoDB, this would usually mean updating specific fields within a document without replacing the entire document. You would typically specify only the fields that need to be updated, and the existing document would be modified accordingly, leaving other fields unchanged.
  3. Update: In the context of MongoDB's native operations, "update" refers to the operation of modifying one or more fields within a document. MongoDB provides various update operators (such as $set, $unset, $push, $pull, etc.) that allow you to update documents in specific ways. Unlike "PUT", which replaces the entire document, and "PATCH", which updates specific fields, "update" allows for more fine-grained control over the modifications you want to make to a document.

In summary: