Mongoose - Promise then() not triggered on save Mongoose - Promise then() not triggered on save mongoose mongoose

Mongoose - Promise then() not triggered on save


I am guessing a funny problem with your code(Just guessing looking at your variable name convention ;-)).

You are saying you use mongoose but you connect using native MongoClient (again guessing based on variable name) you must be connecting using mongoose

const mongoose = require('mongoose');

then just replace your MongoClient with mongoose

then doesn't print anything as nothing is happening there and catch prints error as validation happens before connection


The reason is you are using native client for connecting and using mongoose for modelling which is not the correct way. Do connect to the Mongo DB URI using mongoose and save schema.


You are creating a standard MongoClient connection, this will not effect mongoose models. The connection that created the User model must be open for the various database actions to work. Assuming that the User model was created using the global mongoose object (e.g. mongoose.model('User', userSchema)) then you must call mongoose.connect() to activate the model's connection. If the User model was created via a non-global connection (e.g. mongoose.createConnection()) then you should ensure that the connection is in the open state.