User.findOne() is not a function

findone is not a function(sequelize)
mongodb findone is not a function
user.findone mongoose
user.findone node js
typeerror user findbyid is not a function
mongoose findone returns null
what does findone return mongoose
find is not a function mongoose
passport.use('local-signup', new LocalStrategy({
    // by default, local strategy uses username and password, we will override with email
    usernameField : 'email',
    passwordField : 'password',
    passReqToCallback : true // allows us to pass back the entire request to the callback
(req, email, password, done) => {
    // asynchronous
    // User.findOne wont fire unless data is sent back
    process.nextTick(() => {

    // find a user whose email is the same as the forms email
    // we are checking to see if the user trying to login already exists
    User.findOne({ 'email' :  email },function(err, user){
        // if there are any errors, return the error

        if (err)
            return done(err);

        // check to see if theres already a user with that email
        if (user) {
            return done(null, false, {'errorMessages': 'That email is already taken.'});
        } else {

            // if there is no user with that email
            // create the user
            let newUser            = new User();

            // set the user's local credentials
         = req.body.fullname;
            //          = email;
            newUser.password       = newUser.generateHash(password);

            // save the user
                if (err)
                    return done(err);
                return done(null, newUser);

The above code is in node js using passport js authentication and the code of local-signup is not working.

In the above code i am getting the error:

User.findOne() is not a function.

My schema is all right... please help

You need to (if you're not already) create instance of your data with a model like

var UserDetails = mongoose.model('userInfo', UserDetail);

Now you should be able to use .findOne here.

And make sure you're defining structure for your date inside a collection like..

 var Schema = mongoose.Schema;
 var UserDetail = new Schema({
  username: String,
  password: String
}, {
  collection: 'userInfo'

findOne() is not a function · Issue #7584 · Automattic/mongoose , findOne() is not a function error in my code. This is peculiar because I am using this same kind of findOne() syntax successfully all over my  Are you sure User is not located at '../models/User'? Did you export the function findOne like module.exports = {findOne : findOne}; ? – momo Jun 14 '18 at 7:32 solved the problem, had to remove the throws, line and change it with console.log and also the findOne variable.

Kindly, use the code below

module.exports = User = mongoose.model('user', UserSchema)

User should be the model name and remember to define const UserSchema = new Schema at the top to create a new model in MongoDB and

user should the route where you have the'/user') (req, res) => { code here }

with this, you are exporting the mongoose schema to the route user, this which enables findOne to be seen as a mongoose function.

User.findOne().exc is not a function, var express = require('express'); var router = express.Router(); var User = require​('../models/user'); // GET / profile router.get('/profile', function  Your User.js exports a function not model, also looks like it requires 2 parameters – 1565986223 May 15 '19 at 4:00 can you please share index.js file in models – Dep May 15 '19 at 4:06 add a comment |

maybe you did not export the Model from your User model folder. eg: module.exports = User = mongoose.model("users", UserSchema);

TypeError: User.findOne is not a function - node.js - html, listen(port, () => console.log('Example app listening on port ${port}!')); console log TypeError: Todo.createDocument is not a function at router.route  User.findOne ().exc is not a function. Using this code below, when I try to log in this error message appears "User.findOne ().exc is not a function". this is near impossible to read without the code being in the code blocks properly.

I also had this situation where:

const User = require('../../mongoose/User');

returned 'findOne is not a function'

But by changing to:

var User = require('../../mongoose/User');
User.findOne(...); worked. Hope I helped someone !

Mongoose Model.findOne not a function - node.js - html, findOne(), but I keep getting the error TypeError: User.findOne is not a function I have the model setup like so: const mongoose = require("mongoose"); const  It may be because you are not using the correct mongoose model or your mongoose model isn't used correctly. Only a valid mongoose model has a findOne function

Export the user Model from models directory from file named user.js.

module.exports.User = User

Then Load User model from any other

const {User} = require('../models/user.js');

Note : I'm assuming user models file is named user.js

mongoose.Model.findOne JavaScript and Node.js code examples , findOne().then(token => { debug('global token received! it('should report error when logged user is not the same as the requested one', async () => { const id findOne({_id:, userId: req.user.sub}, function(err, user){ if (err)  Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. Learn more Ssequelizejs, MySQL and passportjs user.findOne not a function

Mongoose v5.9.16: Queries, A query also has a .then() function, and thus can be used as a promise. Executing; Queries are Not Promises; References to other documents; Streaming For findOne() it is a potentially-null single document, find() a list of documents, count()  But then will execute the query and will not return the promise so its not working like i wan't it. I would use it like this: user . findMinOne ( { 'email' : '' } ) . populate ( 'groups' ) . exec ( function ( err , user ) { // Here, where all other errors will came up, i will get the err if no user is found }

db.collection.findOne(), The findOne() method always includes the _id field even if the field is not explicitly specified in the projection parameter. 0 or false to exclude. The projection  Found what was causing my case of done is not a function. When using passReqToCallback: true the parameters need to be updated: function(req, username, password, done)

.findOne(), To locate the user whose username is "finn" in your database: var finn = await Users.findOne({ username: 'finn' }); if (!finn) { sails.log('Could not find Finn, sorry. Μαθαίνω να χρησιμοποιώ js διαβατηρίου στην εφαρμογή φόρμας μου και χρησιμοποιώ ένα αντικείμενο χρήστη σε μια εφαρμογή που χρησιμοποιεί αυτό το μοντέλο για να αποθηκεύσει έναν χρήστη στη βάση δεδομένων, αλλά όταν

  • how we're supposed to know what User is?
  • can you give an example on kexjs for postgresql i'm getting the same error user .findone isn't a function , and i don't know where to start to look for this problem
  • Sorry @sasharomanov. I don't know how to get it on postgresql. But make sure you are acquiring the model where you are using .findOne
  • Why -1 ? Please give an explanation that would clarify the reason
  • It was really worked!