• Register
0 votes
397 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 212 views
212 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 4 views
4 views
Problem: Any help: no 'access-control-allow-origin' header is present on the requested resource
asked Mar 19 Wafa Abu Yousef 6.1k points
0 votes
1 answer 3 views
3 views
Problem: In my computer Their are some error is occurred and i really want it's answer if anyone of you know how can i shortout from this then please answer me.
asked 2 days ago niyatiry 3.2k points
0 votes
1 answer 2 views
2 views
Problem: I am trying to integrate Socket.io with Angular and I'm having difficulties making a connection from the client-side to the server. I've looked through other related questions but my issue is happening locally, so there's no web server in the middle. ... of websockets. I tried all sorts of different options in the socket.connect call, but nothing worked. Any help would be appreciated.
asked 3 days ago Atik03 10.1k points
1 vote
1 answer 20 views
20 views
Problem : I tried installing but that didn't work , Its throw this error : node.js:201 throw e; // process.nextTick error, or 'error' event on first tick ^ Error: Cannot find module 'mongoose' at Function._resolveFilename (module.js:334:11) at Function._load (module.js ... Function._load (module.js:310:12) at Module.require (module.js:357:17) Does anyone know what it is and how to solve it? Thanks
asked Mar 29 Shovo210 14k points
0 votes
1 answer 301 views
301 views
I'm trying to render html files, but I'm having an issue. This works. app.get('/randomlink', function(req, res) { res.sendFile( __dirname + "/views/" + "test2.html" ); }); But I don't want to copy and paste dirname thingy over and over, so I tried this ... // test2.html exists in the views folder }); Here's the error. path must be absolute or specify root to res.sendFile Please help me solve this.
asked Jan 23 khaled 280 points
0 votes
1 answer 15 views
15 views
What is the difference between node js and react js?
asked Oct 10, 2020 sikandar 2.4k points