Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

271
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!