2015-11-01 64 views
1

我需要一个help.i想要使用mongoDB和Node.js.从集合中获取所有数据。我正在下面解释我的代码。如何使用mongoDB和Node.js从集合中获取所有文档

exports.readProfileData=function(req,res){ 
    db.profile.findOne({ 
     colgid:1 
    },{ 
     colgname:1, 
     colgSname:1, 
     address:1, 
     contno:1, 
     email:1 
    },function(err,docs){ 
     if(!err){ 
      if(docs){ 
       res.send(docs); 
      } 
     } 
    }); 
} 

在这段代码中我正在取出由曲线收集单一的文件,但我需要获取所有存在曲线收集文件并将其发送到客户端side.Please帮助我。

回答

0

使用find({})这将捕获所有:

exports.readProfileData=function(req,res){ 
    db.profile.find({},{ 
     colgname:1, 
     colgSname:1, 
     address:1, 
     contno:1, 
     email:1 
    },function(err,docs){ 
     if(!err){ 
      if(docs){ 
       res.send(docs); 
      } 
     } 
    }); 
} 
相关问题