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

265
Vistas
Mongoose - model.find is not a function

this is a very odd one that I don't quite understand why it's not working. I have 2 functions, one to add an item to a MongoDB collection. That is working fine. I have another function which is meant to search the collection for items matching my query. For some reason, the search function is returning 'not a function' and I'm wondering if anyone can help?

When I try and call findSimilarEvents() I get TypeError: event.find is not a function back in the console

My model:

var mongoose = require('mongoose');

const eventSchema = new mongoose.Schema({
    eventTime: { type: Date, default: Date.now() },
    eventLoggedFrom: String,
    eventData: Object,
    eventID: String,
    ticketID: { type: String, default: "" },
    ticketStatus: { type: String, default: "" },
    eventLastUpdated: { type: Date, default: Date.now() },
})

module.exports = mongoose.model('event', eventSchema);

My working function:

exports.addEventToDB = async function(eventData, eventLoggedFrom, EventID) {

  const event = new EventModel({
    eventLoggedFrom: eventLoggedFrom,
    eventData, // this is a JSON object
    eventID: eventID
  });
  await event.save();
}

My non-working function:

exports.findSimilarEvents = async function(eventData, eventLoggedFrom) {

  const event = new EventModel();
  let similarEvents = await event.find({
    eventData: eventData
  });
  for (var i = 0; i = similarEvents.length; i++) {
    console.log("found similar event");
    console.log(similarEvents[i]);
  }

}

I'm happy to provide any other info if anyone has any thoughts!

Thank you in advance

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

exports.findSimilarEvents = async function(eventData, eventLoggedFrom) {

  
  let similarEvents = await EventModel.find({
    eventData: eventData
  });
  for (var i = 0; i = similarEvents.length; i++) {
    console.log("found similar event");
    console.log(similarEvents[i]);
  }

}

try this ...

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