0

I search to update 1 data who is in my last array, my code just add this data in firestore but I don't com in my last array.This is my database

I want to update isPay at true.

On my database futurOrder is array and need to enter in my last index of futurOrder and update isPay at true

firebase.getUserOrder().doc(userSession.uid).update({ isPay : true })

Else I have try this but with this code I add new index I don't update last index firebase.getUserOrder().doc(userSession.uid).update({ futurOrder: firebase.addInArray().arrayUnion({ isPay: true, }) })

Cyril
  • 1
  • 3
  • Can you please show some code? – AsifM Oct 23 '20 at 21:50
  • Yes I modify my question with my code. But this add isPay at the racine of my document but I need to enter in my array and update data at the last array. I have try with arrayUnion but this add new index in futurOrder – Cyril Oct 23 '20 at 22:20
  • You can't update an item in an index by its array. You will have to: 1) load the document, 2) get the current array contents from there, 3) update that array in your application code, 4) write the array back to the database. – Frank van Puffelen Oct 23 '20 at 22:28
  • The `arrayUnion({ isPay: true, })` operation doesn't **update** an item in an array. It either **adds** the item if it's not there yet, or it does nothing if the item already exists. To update an item at an index, you'll to do what I said above and in the questions I linked.. – Frank van Puffelen Oct 23 '20 at 22:33
  • I hope I can get the last index and update datas but okey I just get my last datas, I delete the last and I add the new datas with isPay : true – Cyril Oct 23 '20 at 22:38

0 Answers0