我有一些MongoDB集合,並且需要在我的站點中顯示它們,使它成爲一個動態頁面(它是團隊成員,如果刪除或添加1要刷新頁面上)NodeJS從MongoDB中檢索多個數據並在Jade上顯示(Pug)
我的收藏是像(mongodb的終端):
db.capitao.find() = { "_id" : ObjectId("59a6b67519404d41f9988524"), "nome" : "Renato", "email" : "[email protected]
om", "imagem" : "renato.png", "curso" : "Engenharia Mecânica", "lider" : 1 }
db.chassi.find() = {
{ "_id" : ObjectId("59a6b69f19404d41f9988529"), "nome" : "Carlos", "email" : "[email protected]
", "imagem" : "possebon.png", "curso" : "Engenharia Mecânica", "lider" : 1 }
{ "_id" : ObjectId("59a6b69f19404d41f998852a"), "nome" : "Felipe", "email" : "[email protected]
l.com", "imagem" : "brunetto.png", "curso" : "Engenharia Mecânica", "lider" : 0 }
{ "_id" : ObjectId("59a6b69f19404d41f998852b"), "nome" : "Isabelle", "email" : "[email protected]
gmail.com", "imagem" : "isabelle.png", "curso" : "Engenharia Mecânica", "lider" : 0 }
{ "_id" : ObjectId("59a6b69f19404d41f998852c"), "nome" : "Mateus Dandolini Pescador", "email" : "[email protected]
r", "imagem" : "pescador.png", "curso" : "Engenharia Mecânica", "lider" : 0 }
{ "_id" : ObjectId("59a6b69f19404d41f998852d"), "nome" : "Marcelino Colla Junior", "email" : "[email protected]",
"imagem" : "marcelino.png", "curso" : "Engenharia Mecânica", "lider" : 0 }
我index.js(僅試圖從 「capitao」 檢索在前):
router.get('/', function(req, res,next) {
var resultArray = {
capitao : [],
chassi : []
};
var db = req.db;
//var collectionCapitao = db.collection('capitao').find();
var collectionCapitao = db.get('capitao');
//var chassi = db.collection('chassi').find();
collectionCapitao.find({},{},function(e,docs){
res.render('index', {
env: env,
capitao: collectionCapitao
});
});
});
我index.jade:
.row
each membro, i in capitao
.col-sm-4
.team-member
img.mx-auto.rounded-circle(src='/img/team/#{membro.imagem}', alt='#{membro.nome}')
h4 membro.nome
p.text-muted membro.curso
ul.list-inline.social-buttons
li.list-inline-item
a(href="mailto:#{membro.email}")
i.fa.fa-envelope
我的問題:
- 所有屬性在玉返回undefined(解決)
- 「capitao」 只有1分的記錄,但它產生的31條記錄翡翠(已解決)
- 如何獲取index.js中的MULTIPLE集合併發送它們做Jade?
您不應該發佈卡洛斯,菲利普和伊莎貝爾的電子郵件地址。 –
它應該是'res.render( '索引',{ ENV:ENV, capitao:文檔 });','不capitao:collectionCapitao' –
固定,@JeremyThille – alvarosps