DEV Community

Cover image for Why am I getting $parent in keys?
Nimit Savant
Nimit Savant

Posted on

Why am I getting $parent in keys?

Background

While traversing through a mongoose object, you might get a properties like $_parent, $_schema and $_path. Which are added to an object by Mongoose package for its own internal use or maybe future use by us.

Problem

When you're trying, to traverse through an object which is mongoose object, you'll get these keys which are not expected from you. But you still get them! And in your code you don't know where they're coming from.

Solution

To avoid these properties, you can just use a simple toObject() method to this mongoose object and you'd find that to be a normal Object. Without the hidden properties.


Why I wrote this article

There were no solutions for this silly problem that I was looking on the internet, at last I asked this to co-pilot and it responded me with this hint.

Top comments (0)