Mongoose JS findOne always returns null Mongoose JS findOne always returns null mongodb mongodb

Mongoose JS findOne always returns null


Mongoose pluralizes the name of the model as it considers this good practice for a "collection" of things to be a pluralized name. This means that what you are currently looking for in code it a collection called "users" and not "user" as you might expect.

You can override this default behavior by specifying the specific name for the collection you want in the model definition:

var userModel = mongoose.model('user', userSchema, 'user');

The third argument there is the collection name to be used rather than what will be determined based on the model name.