再次获取[object Object]但似乎不是模型问题

时间:2017-10-18 23:15:01

标签: mongodb express twig mongoose-schema swig-template

我正在尝试在使用带有swig / twig的for循环时弄清楚如何访问模型的author.id。所有其他人打印出来都很好但ap.author.id是我尝试过的问题ap.author.idap.author.id.typeap.author.id.ref只是希望它看起来像我之前的问题{{3}但据我所知,它似乎与模型无关。此外,当我console.log aps时,它会显示所有文档,而有意义的路径将是ap.author.id。我没有想法,我错过了什么?

循环:

{%  for ap in aps  %}
  <tr>
   <td>{{ap.name}}</td>
   <td>{{ap.manufacturer}}</td>
   <td>{{ap.model}}</td>
   <td>{{ap.type}}</td>
   <td>{{ap.notes}}</td>
   <td>{{ap.author.id}}</td>
 </tr>

{%endfor%}

型号:

var accessPointsSchema = new Schema({
  name: {type: String},
  type: {type: String},
  manufacturer: {type: String},
  model: {type: String},
  IPAdress: {type: String},
  MACAdress: {type: String},
  range: {type: Number()},
  bands: {type: String},
  channel: {type: Number},
  dateBought: {type: Date},
  PoE: {type: Boolean},
  assetNumber: {type: Number},
  warrantyExpiration: {type: Date},
  location: {type: String},
  notes: {type: String},
  author: {
      id: {
         type: mongoose.Schema.Types.ObjectId,
         ref: "User"
      },
      email: String
   }
});

1 个答案:

答案 0 :(得分:0)

当你console.log author.id时,你会收到一个包含所需ID的对象但你需要通过author._id来访问它,否则你会得到[object Object]错误,因为它是试图将对象输出到字符串中。