• Register
0 votes
266 views

Problem :

While I am trying to update the MongoDB document facing Deprecation Warning as below:

(node:71307) [DEP0079] DeprecationWarning: Custom inspection function on Objects via .inspect() is deprecated

 My Software Specs as below :

Node ver : v10.5.0,

db ver : v3.6.5,

Mongoose ver : mongoose@4.1.12

My MongoDB code for your reference as follows:

Myground.findById(mygroundId, function(err, mypground){
    if(err){
        console.log(err);
    } else {
        console.log(myground.celebrity);
        Celeb.create(celebData, function(err, celeb){
            if(err){
                console.log(err);
            } else {
                //save comment
                celeb.save();
                myground.celeb.push(celeb);
                myground.save();
                console.log(celeb);
                //req.flash('success', 'Created a comment!');
            }
        });
    }
});
6 5 3
7,540 points

1 Answer

0 votes

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.

9 7 4
38,600 points

Related questions

0 votes
1 answer 140 views
140 views
Problem : I have recently updated the node to 7.2.1 and noticed that there is the warning coming as below : (node:4346) DeprecationWarning: Calling an asynchronous function without callback is deprecated. Why is this 4346 ? I only have 2000 lines of code in the js file, so it must not be the line-number. Where should I look for that code?
asked Dec 10, 2019 alecxe 7.5k points
0 votes
1 answer 7 views
7 views
What is the difference between node js and react js?
asked Oct 10 sikandar 2.4k points