[英]How to connect to mongodb and How to print list of all collection from a dabase in mongodb using node.js program
[英]How to get all document from a collection using mongoDB and 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);
}
}
});
}
在這段代碼中,我從配置文件集合中獲取單個文檔,但是我需要獲取配置文件集合中存在的所有文檔,並將其發送給客戶端。請幫助我。
使用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);
}
}
});
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.