search

Home  >  Q&A  >  body text

javascript - How to delete a message in mongoDB using js

  1. mongoDB stores articles

  2. A message has time, title, content, publisher and _id

  3. Using JavaScript

  4. The express framework of node.js used

  5. Please post the code Thank you

给我你的怀抱给我你的怀抱2799 days ago798

reply all(2)I'll reply

  • 世界只因有你

    世界只因有你2017-06-08 11:04:02

    May I ask what middleware the poster uses to operate mongodb? Here I will write it according to mongoose:

    //因为不清楚楼主想要通过什么条件进行删除,通过id肯定不靠谱
    //这里通过作者和文章标题进行查询并删除,使用的是findOne值查询一个
    Passage.findOneAndRemove({author:"LiMing",title:"helloworld"}).exec();

    reply
    0
  • 代言

    代言2017-06-08 11:04:02

    db.person.remove(“name”:"ziling")


    db.collection("tb2").insert([{"name":"wilson001","age":21},{"name":"wilson002"},{"age":22}],function(err,result){})

    db.collection("tb2").remove({"name":"wilson002"},function(err,result){});

    db.collection("tb2").update({"name":"wilson001"},{$set:{"age":100}},function(err,result){});

    db.collection("tb2").find({"name":"wilson001"}).toArray(function(err,result){});

    reply
    0
  • Cancelreply