In node, working with firestore models can be tricky. When you use a new keyword to initialise an object, Firestore throws error.

Firestore doesn't support JavaScript objects with custom prototypes (i.e. objects that were created via the "new" operator)

There are two ways to solve this.

Solution 1

The simplest way to do it to stringify and parse JSON, but it won’t be effective when you are working with Date/Timestamp object.


Solution 2

To solve this I created a parse method.

This method is capable of converting to array as well as object to plain.

Hope this helps.

If you liked this article, you can buy me a coffee



Kumar Rohit

Kumar Rohit

I like long drives, bike trip & good food. I have passion for coding, especially for Clean-Code.

Leave a comment