#[Mongoose] .findOne is not a function

10 messages · Page 1 of 1 (latest)

narrow fossil

Hello!

Command

async execute(interaction) {
    const data = await schema.findOne({ User: interaction.user.id })
}

Schema

const mongoose = require('mongoose');

const Schema = new mongoose.Schema({
    User: String,
});

module.export = mongoose.model('user', Schema);

I tried looking on the internet but couldn't find any solution that works.

stray impBOT
  • Consider reading #how-to-get-help to improve your question!
  • Explain what exactly your issue is.
  • Post the full error stack trace, not just the top part!
  • Show your code!
  • Issue solved? Press the button!
  • Marked as resolved by OP
summer juniper

@narrow fossil
Definition of schema

narrow fossil
summer juniper

@narrow fossil
Error or anything, added console logs tp make sure it reaches?

narrow fossil

TypeError: schema.findOne is not a function

celest sapphire
narrow fossil

ohh

celest sapphire

Also, you might want to name the imported variable as "model" instead of "schema" since that's what type it is
Not necessarily, but would help you if you're debugging and wonder why mongoose's docs dont show the types on a schema that you're expecting to be there