Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

edit mongodb array if checkbox is checked

//////////NODE BACKEND
router.post("/deletePurposOfDating", async (req, res) => {
  const { email, goal } = req.body

  try {
    let user = await User.updateOne({ email }, { $pull: { goal } })

    res.status(200).json({
      message: "Update successful",
      success: true,
      user,
    })
  } catch (error) {
    return res.status(401).json({
      success: false,
      message: "Update failed",
      error,
    })
  }
})
    
////////////FRONTEND VUE METHOD
setPurpose(select, i) {
      let myCheckbox = document.querySelectorAll(
        `.myCheckbox .vs-checkbox-con [type='checkbox']`
      )[i]
      if (myCheckbox.checked)
        this.$store.dispatch("updatePurposeOfDating", select)
      else this.$store.dispatch("deletePurposOfDating", select)
    },
 
PREVIOUS NEXT
Tagged: #edit #mongodb #array #checkbox #checked
ADD COMMENT
Topic
Name
5+9 =