javascript - How to update() an array of maps-objects on Firestore in Angular or Angularfirestore? - Stack Overflow

I know how to READ and WRITE a document in Firestore, But how does one update() a Value of and object i

I know how to READ and WRITE a document in Firestore, But how does one update() a Value of and object in an array of Maps without removing/deleteing? Just changing one value if needed.

I have a Form that includes a FormArray, that are able to edit as an when there is an update on the price list.

product = {
  id: "product id",
  brand: "Brand Name",
  model: "This is the model of the brand"
  lists: [
    { location: "Location 1", price: "0.00" },
    { location: "Location 2", price: "0.00" }
  ]
}

Component.ts

    export class PageComponent implements OnInit {
      productDoc: AngularFirestoreDocument<Product>;
      product: Observable<any>;
    }

constructor(private afs: AngularFirestore) {}

  update() {
    this.productDoc.update({ amount: this.updatedProduct });
  }

Appreciate to shine some light on it, Thank You!

I know how to READ and WRITE a document in Firestore, But how does one update() a Value of and object in an array of Maps without removing/deleteing? Just changing one value if needed.

I have a Form that includes a FormArray, that are able to edit as an when there is an update on the price list.

product = {
  id: "product id",
  brand: "Brand Name",
  model: "This is the model of the brand"
  lists: [
    { location: "Location 1", price: "0.00" },
    { location: "Location 2", price: "0.00" }
  ]
}

Component.ts

    export class PageComponent implements OnInit {
      productDoc: AngularFirestoreDocument<Product>;
      product: Observable<any>;
    }

constructor(private afs: AngularFirestore) {}

  update() {
    this.productDoc.update({ amount: this.updatedProduct });
  }

Appreciate to shine some light on it, Thank You!

Share Improve this question edited Sep 1, 2020 at 1:24 Frank van Puffelen 601k85 gold badges890 silver badges860 bronze badges asked Aug 31, 2020 at 23:31 syahiruddinsyahiruddin 5168 silver badges23 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 8

There is no way to change a value in an array. You'll either have to remove the old bination of values and add the new bination, or have to:

  1. Read the document.
  2. Get the entire array from that document.
  3. Modify the array in your application code.
  4. Write the modified array back to the database in its entirety.

Alternatively, you can store the lists in a map field rather than an array field, meaning that you give a name to each set of values - and you can the use dot notation to update the nested field.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745352784a4623935.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信