• Register
0 votes
346 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

Please log in or register to answer this question.

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 176 views
176 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 13 views
13 views
What is the difference between node js and react js?
asked Oct 10, 2020 sikandar 2.4k points
0 votes
1 answer 1.7K views
1.7K views
Problem : I am getting following error: Deprecationwarning: collection.ensureindex is deprecated. use createindexes instead. Where is above error coming from? I am not at all using ensureIndex or createIndex in my Nodejs application anywhere. I am using the yarn package manager. ... ', { useNewUrlParser: true }); const myapp = express(); Does anyone ever faced this issue? Any solution on it?
asked Dec 10, 2019 alecxe 7.5k points
0 votes
1 answer 116 views
0 votes
1 answer 14 views
14 views
I am new to this. I was doing that but I got into some problems.
asked Nov 4, 2020 TeamScript 10.1k points