derek
derek

Reputation: 10257

promise parameter from firestore set is undefined

I am trying to create a new document and then do something inside the promise using the following way :

      firestore.collection('users').doc(uid).set({name: "testName"})
      .then(res => {
        console.log("set data correctly with ", res);
      }).catch(err => {
        console.log('something went wrong '+ err)
      });

It indeed went into the then promise. However, the res is empty! I got:

set data correctly with undefined

Upvotes: 0

Views: 56

Answers (2)

Doug Stevenson
Doug Stevenson

Reputation: 317928

Take a look at the API documentation for DocumentReference.set(). The method is defined like this:

set(data: DocumentData, options?: SetOptions): Promise<void>

Note that the method returns a Promise that contains void. That means set() doesn't yield any objects or data at all.

So, if you use that promise, it will be delivered nothing. So it's working as expected.

Upvotes: 0

Frank van Puffelen
Frank van Puffelen

Reputation: 600110

The DocumentReference.set() method returns a Promise<void>. So it is expected that there's no value passed to then().

Upvotes: 1

Related Questions