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){});
相關文章:
