簡體   English   中英

從MongoDB中查看帶有Pug的Pug中的所有數據

[英]Viewing all data in Pug, from MongoDB with express issue

我有以下Pug文件:

extends layout

block content   .main.container
    .row
      .col-md-8.col-md-offset-2
        h1.display-4.m-b-2 All Current Projects
        p Projects
         ul
         each project in project
          li #{title}

以及以下GET請求:

// GET /projects
router.get('/projects', mid.requiresLogin, function (req, res) {   
  project.find({}), function (err, docs) {
    if (err) res.json(err);
    else return res.render('project', { title: project.title });
  });
});

我似乎無法通過帕格模板顯示該項目的詳細信息。 我已經嘗試了很多事情,但是很明顯我必須做一些簡單的錯誤。 我目前收到"Cannot read property 'length' of undefined"的錯誤,但同時定義了項目和標題,均使用以下導出的項目模型:

const ProjectSchema = new Schema({
  title: {
    type: String,
    required:[true, "Title is required"],
  },
});

如果有人可以提供幫助,我將不勝感激。 謝謝

嘗試這個

router.get('/projects', mid.requiresLogin, function (req, res) {   
  project.find({}, function (err, docs) {
    if (err) res.json(err);
    else return res.render('project', { title: docs.title });
  })
});

請注意,您的括號在project.find({}),處未完全閉合project.find({}),並且project.tittle應該是docs.tittle

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM