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

网公网安备