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

267
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
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