Getting [object Object] again but doesn't seem to be model issue

30 Views Asked by At

I am trying to figure out how to access the author.id for a model when using a for loop with swig/twig. All of the others print out just fine but the ap.author.id is the issue I have tried ap.author.id, ap.author.id.type and ap.author.id.ref just hoping it was like my issue before seen HERE but it seems it is not model related far as I can tell. Also when I console.log out aps it shows all the documents and the path that makes sense would be ap.author.id. I am out of ideas, what am I missing?

Loop:

{%  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 %}

Model:

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

There are 1 best solutions below

0
AudioBubble On

When you console.log author.id you get back an object that will contain the ID needed but you need to access it by doing author._id otherwise you will get the [object Object] error because it is trying to output an object into a string spot.