Solution :
I was also facing this deprecation warning and the unexpected behavior when I had accidentally used the Model.find() instead of Model.findOne()
So my incorrect code looked like below:
Us.find(que)
.then(us => {
console.log(us.emailSettings.confirmToken)
})
Here with an ordinary object this would have failed with below error
TypeError: Cannot read property 'confirmToken' of undefined
however with an mongo document object apparently it gives above deprecation warning.
Also to solve your problem you must use the useNewUrlParser and useCreateIndex. See the sample code snippet below :
mongoose.connect(
config.databaseUrl,
{
useNewUrlParser: true,
useCreateIndex: true
}
)
Or
mongoose.set("useCreateIndex", true);
mongoose.connect(
config.databaseUrl,
{
useNewUrlParser: true
}
);
Finally you need to upgrade to the 5.2.10 and also set
mongoose.set('useCreateIndex', true);
And your issue will be resolved.