Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: Argument "data" is not a valid Document. Input is not a plain JavaScript object

I am getting the error

Error: Argument "data" is not a valid Document. Input is not a plain JavaScript object.

when updating a document, using firebase admin SDK. Here the Typescript code.

var myDoc = new MyDoc();
myDoc.Public.Name = "Jonh Doe" //setup up content

admin.firestore()
     .collection('MyDocs')
     .doc("Id1")
     .set(myDoc);
like image 358
MiguelSlv Avatar asked Feb 08 '18 17:02

MiguelSlv


2 Answers

I did something similar:

var myDoc = <MyDoc> {
    Public: {
        Name: "Jonh Doe"
    }
}

It is semantically the same, I just think it is a bit cleaner.

like image 116
Chad Bingham Avatar answered Sep 18 '22 13:09

Chad Bingham


In case some else bump into the same issue, the solution is to simple use Json to instantiate the object, like this:

var myDoc = {
        Public: {
            Name: "Jonh Doe"
        }
    } as MyDoc; //keep type to still get typescript compiler validations
like image 38
MiguelSlv Avatar answered Sep 18 '22 13:09

MiguelSlv