Why am I getting $parent in keys?
Nimit Savant

Nimit Savant @nimit2801

About: A community enthusiast, who loves to work with communities. Give talks on Backend Development, Open Sourcing and Quality Assurance.

Location:
Bangalore, India
Joined:
May 22, 2020

Why am I getting $parent in keys?

Publish Date: Dec 28 '23
1 0

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.

Comments 0 total

    Add comment