devOP1
devOP1

Reputation: 477

How to add firestore document with AutoID from Cloud Functions?

In my functions I have the following:

await admin.firestore()
  .collection("development")
  .doc("development")
  .collection("users")
  .doc(userId)
  .collection("tokens")
  .doc("{autoId}")
  .set(token, {merge: true});

In the tokens collection, I want to create a document with an autoID. Everything else seems to be working fine. However, when I check my firestore, the document is named {autoId} instead of generating an actual ID.

Any help is appreciated! :)

Upvotes: 0

Views: 145

Answers (1)

LeadDreamer
LeadDreamer

Reputation: 3499

Just leave the argument to the last .doc blank - i.e. .doc(). "{autoId}" is NOT a flag to Firestore - it's just a string.

Upvotes: 2

Related Questions