Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

166
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda