const express = require('express')
const mongoose = require('mongoose')
var app = express()
var Data = require('./noteSchema')
mongoose.connect('mongodb://localhost/newDB')
mongoose.connection.once("open", () => {
console.log("Connected to the database!")
}).on("error", (error) => {
console.log("Failed to establish connection"+ error)
})
app.post("/create", (req,res) => {
var note = new Data ({
note: req.get("note"),
title: req.get("title"),
date: req.get("date")
})
note.save().then( () => {
if( note.isNew == false){
console.log("Data saved successfully!")
res.send("Data saved successfully!")
}else{
console.log("Failed to save data!")
}
})
})
app.get('/fetch', (req, res) => {
Data.find({}).then( (DBitems) => {
res.send(DBitems )
})
})
app.post("/delete" , ( req , res ) =>{
Data.findOneAndDelete({
_id: req.get("id")
})
console.log("Deleted successfully!")
res.send("Deleted!")
})
var server = app.listen (8081,"192.x.x.x",()=>{
console.log("Server is up and running!")
})
I've attempted multiple solutions but I'm still unable to find the right one.
It appears that there have been some changes in the latest update.
Error message: MongooseError: Model.findOneAndDelete() no longer accepts a callback