2015-11-01 67 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); 
      } 
     } 
    }); 
} 
相關問題