javascript - 怎么用js刪除mongoDB一條信息
問題描述
mongoDB存的是文章
一條信息有時間,標題,內容,發表者和_id
用JavaScript實現
用的node.js的express框架
請貼代碼 謝謝
問題解答
回答1:敢問樓主用的是什么中間件操作mongodb呢?這里我就按mongoose的寫法來吧:
//因為不清楚樓主想要通過什么條件進行刪除,通過id肯定不靠譜//這里通過作者和文章標題進行查詢并刪除,使用的是findOne值查詢一個Passage.findOneAndRemove({author:'LiMing',title:'helloworld'}).exec();回答2:
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){});
相關文章:
1. boot2docker無法啟動2. docker-compose中volumes的問題3. docker容器呢SSH為什么連不通呢?4. 關docker hub上有些鏡像的tag被標記““This image has vulnerabilities””5. java - SSH框架中寫分頁時service層中不能注入分頁類6. docker安裝后出現Cannot connect to the Docker daemon.7. node.js - antdesign怎么集合react-redux對input控件進行初始化賦值8. 關于docker下的nginx壓力測試9. nignx - docker內nginx 80端口被占用10. 老師,按tab鍵不起作用怎么回事

網公網安備