Lulutho Mgwali
Lulutho Mgwali

Reputation: 903

How to Firebase set into a doc map value

I have a Firebase collections structure that I would like to update however only the phonebook(map) section of a specified doc.

enter image description here

The below code was my attempt however I get the error Invalid document reference. Document references must have an even number of segments. I'm new to Firebase so I think the is a concept in not understanding here

insertPhonebookEntry(entry: any) {
  if (entry.id) {
    this.db.doc(entry.id).set({
    PhoneBook: {
      Name: entry.name,
      PhoneNumber: entry.phonenumber
    }
  });
}

Upvotes: 3

Views: 603

Answers (1)

Doug Stevenson
Doug Stevenson

Reputation: 317352

Since you didn't say what exactly entry.id is in your case, I'm going to assume that it's just the random ID that Firestore assigned to the document you're trying to fetch. That's not enough information to query it back. You'll need to specify the name of the collection as well, in order to provide a full path to the document:

this.db.collection('PhonebookEntries').doc(entry.id).set(...)

Upvotes: 1

Related Questions