Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

(node:71307) [DEP0079] DeprecationWarning

Try to update MongoDB document Getting Deprecation Warning as

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

Node version v10.5.0, db version v3.6.5, Mongoose version [email protected]

Campground.findById(campgroundId, function(err, campground){
    if(err){
        console.log(err);
    } else {
        console.log(campground.celebrity);
        Celebrity.create(celebrityData, function(err, celebrity){
            if(err){
                console.log(err);
            } else {
                //save comment
                celebrity.save();
                campground.celebrity.push(celebrity);
                campground.save();
                console.log(celebrity);
                //req.flash('success', 'Created a comment!');
            }
        });
    }
});
like image 533
Kiran Ghatage Avatar asked Jul 20 '18 06:07

Kiran Ghatage


4 Answers

In order to not get the deprecation message you can upgrade to mongoose version 5.2.10 or later according to this Github mongoose issue and the set the following at a proper location in code:

mongoose.set('useCreateIndex', true)
like image 73
King Rayhan Avatar answered Nov 15 '22 09:11

King Rayhan


You have to not worry about this error this is mongoose warning . Actually Mongoose use inspect() to debug output . they will update it may be before node 12.x . For now it is safe to use this.

Nothing to worry.

Check this info. https://nodejs.org/api/deprecations.html#deprecations_dep0079_custom_inspection_function_on_objects_via_inspect

DEP0079: Custom inspection function on Objects via .inspect()# Type: Runtime

Using a property named inspect on an object to specify a custom inspection function for util.inspect() is deprecated. Use util.inspect.custom instead. For backward compatibility with Node.js prior to version 6.4.0, both may be specified.

If you want more detail, see this . This is under progress. Warning will come in node 10

https://github.com/Automattic/mongoose/issues/6420

like image 14
Himanshu sharma Avatar answered Nov 15 '22 08:11

Himanshu sharma


upgrade to 5.2.10 and set

  mongoose.set('useCreateIndex', true);
like image 3
viz Avatar answered Nov 15 '22 09:11

viz


Another way to set it is...

mongoose.connect(
    "mongodb://<user>:<password>@<url>",
    { 
      useNewUrlParser: true, 
      useCreateIndex: true 
    }
  )

More information can be found here: https://github.com/Automattic/mongoose/issues/6890

like image 3
hp001 Avatar answered Nov 15 '22 08:11

hp001