Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
84 views
in Technique[技术] by (71.8m points)

javascript - How to delete dynamic data from mongoose collection by onclick?

I am new to mongodb, I am running through a problem, Like I want to delete the data dynamically by onclick but it shows me an error Argument passed in must be a single String of 12 bytes or a string of 24 hex characters

My code is

app.js

router.delete('/Delete_Data/:itemIndex',  (request, response) => {
    const itemIndex = request.params.itemIndex
    item.findOneAndRemove({_id: itemIndex}, (err, data)=> {   
        if(err){
            console.log(err);
            return response.status(500).send();
        }
        else{
            console.log({data});
            return response.json({data});
        }
    });
    
});

page1.js

I have used fetch DELETE method

async function deleteLSItem(itemIndex){
  let options = {
    method: 'DELETE',
    headers: {
      'Content-Type': 'application/json'
    }
  };
  const response = await fetch('/Delete_Data/'+itemIndex, options);
  const data = await response.json();
  console.log(data);
}
question from:https://stackoverflow.com/questions/65920473/how-to-delete-dynamic-data-from-mongoose-collection-by-onclick

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...