Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

159
Views
How can I get my ejs to display the length of a mongoose array?

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

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!