I am making a follow system this is the schema.
const usersSchema = new mongoose.Schema({
username: {
type: String,
required: true,
trim: true,
minLength: [5, "Username needs to be at least 5 characters long "],
maxLength: [15, "Username cannot be any longer than 15 characters"],
unique: true,
},
password: {
type: String,
required: true,
minLength:[8, "Password needs to be at least 8 characters long" ]
},
email: {
type: String,
required: true,
unique: true,
},
createdAt:{
type:Date,
default:()=>Date.now()
},
updatedAt:{
type:Date,
immutable:true,
default:()=>Date.now()
},
followers:[{ type: mongoose.SchemaTypes.ObjectId,
ref: 'User',
default:null
}],
following:[{ type: mongoose.SchemaTypes.ObjectId,
ref: 'User',
default:null
}]
})
this is how I try to render the page with the information
<table border="1px">
<th>
S. No
</th>
<th>Username</th>
<th>Followers</th>
<th>Following</th>
<th>Edit</th>
<% data.allUser.forEach((item)=> { %>
<tr>
<td>
<%= k++ %>
</td>
<td>
<%= item.username %>
</td>
<td>
<%= item.followers %>
</td>
<td>
<%= item.following %>
</td>
<td>
<form action="/follow/ <%= item._id%>" method="POST" >
<button id="<%= item._id %>">Follow</button>
</form>
</td>
<% }) %>
<form action="/logout" method="post">
<button>Log out</button>
</form>
i get all the right things when it comes to the username and the buttons but I only get the id's of all the users in the following and followers columns and if I try to add . length at the end I get an error