chichi
chichi

Reputation: 3301

mongoose findOne() is not a function

gooModel.js

//user model

const mongoose = require('mongoose');
const Schema = mongoose.Schema;

const GooSchema = new Schema(
    {
        goo_id: {
            type: String,
            required: true,
            unique: true,
        },
    },
    { collection: 'goo_collection' }
);


module.exports = Goo = mongoose.model(
    'goo',
    GooSchema
);

auth_controller.js

//new user

    const NewGoo = new Goo({
        goo_id,
    })

//function

await NewGoo.findOne({ goo })}

I am getting findOne() is not a function error. I have no idea where I have made a mistake. It creates the collection on my mongo atlas DB (but it is empty). I have exactly the same model in the different route that works. I am super clueless right now.

Upvotes: 2

Views: 418

Answers (1)

eol
eol

Reputation: 24565

I think you should call findOne on the model itself, not on the instance/document which NewGoo refers to. So try changing it to:

await Goo.findOne({ goo })}

Upvotes: 2

Related Questions