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

217
Vistas
Sails.js Find where error javascript by id

I would like to show only one student.but there is the mistake that tell me that is not a function


Current Code

detail: async function (req, res) {
    var thatEvent = await Event.findOne(req.params.eventid);
    if (!thatEvent) return res.notFound();

    var event = await Event.findOne(req.params.eventid).populate(
      "participants"
    );
    if (!event) return res.notFound();
    var participants = await event.participants;
    return res.json(participants);
  },

The is the result of the current code

[
  {
    "createdAt": 1636793903089,
    "updatedAt": 1636793903089,
    "id": 3,
    "role": "student",
    "username": "student1"
  },
  {
    "createdAt": 1636793903089,
    "updatedAt": 1636793903089,
    "id": 4,
    "role": "student",
    "username": "student2"
  },
  {
    "createdAt": 1636793903089,
    "updatedAt": 1636793903089,
    "id": 5,
    "role": "student",
    "username": "student3"
  }
]



After change

 detail: async function (req, res) {
    var thatEvent = await Event.findOne(req.params.eventid);
    if (!thatEvent) return res.notFound();

    var event = await Event.findOne(req.params.eventid).populate(
      "participants"
    );
    if (!event) return res.notFound();
    var participants = await event.participants.find({id:3});
    return res.json(participants);
  },

Then it will show the error that is not a function

error: Sending 500 ("Server Error") response: 
 TypeError: #<Object> is not a function
    at Array.find (<anonymous>)
    at Object.detail [as event/detail] 

The code I edited is below

 var participants = await event.participants.find({id:3});
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I refer the website here to amend my code. The result is correct now.
https://www.codegrepper.com/code-examples/javascript/array.find+find+is+not+a+function

var participants = await event.participants.find(({ id }) => id === 3);

The result

{
  "createdAt": 1636793903089,
  "updatedAt": 1636793903089,
  "id": 3,
  "role": "student",
  "username": "student1"
}
about 4 years ago · Juan Pablo Isaza Denunciar
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