Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

165
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda