Firestore: Add Custom Object to db

Firestore does not support that. But you can use https://github.com/typestack/class-transformer It works perfectly fine for us.


Thx to Fabian Wiles - I got it!

while firebase could send the data inside your object to the database, when the data comss back it cannot instantiate it back into an instance of your class. Therefore classes are disallowed

just save an object like this:

interface Person{
  name: string;
  age: number
}

var person: Person = { name: 'Toxicable', age: 22} ;

You could also serialize your object into JSON and deserialize it back into a regular JavaScript object like

this.collection.doc(sponsor.id).set(JSON.parse( JSON.stringify(sponsor)));

works with deep nesting.


You can also use Object.assign({}, sponsor)

so in yor case it would be

this.collection.doc(sponsor.id).set(Object.assign({}, sponsor));