使用express框架和mongoose在MongoDB删除数据

Posted 山石

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用express框架和mongoose在MongoDB删除数据相关的知识,希望对你有一定的参考价值。

使用remove()删除数据

remove({},function(err,doc){})  // 删除所有数据

remove({age:18},function(err,doc){}); //删除指定条件的数据

User.remove({},function(err,doc){
    if(err){
        console.log(err);
        
    }else{
        console.log(doc);
        
    }
});
User.remove({age:12},function(err,doc){
    if(err){
        console.log(err);
        
    }else{
        console.log(doc);
        
    }
});

 

以上是关于使用express框架和mongoose在MongoDB删除数据的主要内容,如果未能解决你的问题,请参考以下文章