Skip to content

Snappy1

  • Home
  • Android
  • What
  • How
  • Is
  • Can
  • Does
  • Do
  • Why
  • Are
  • Who
  • Toggle search form

[FIXED] android – firestore update() function cast updated data to map

Posted on November 11, 2022 By

Solution 1 :

There is no way to update an item in an array field by its index. Instead you’ll have to:

  1. read the entire array into your application code
  2. update the array in memory
  3. write the entire updated array back to the database

The exception to this is when your array contains unique, unordered values, such as when you for example store an array of the tags for a post. In that case you can use the arrayUnion operator to manipulate the array. However your case looks different, so you’ll have to use the above steps.

This questions comes up quite regularly, so I recommend reading some of these:

  • I need to update a certain array entry of my Map in Firestore
  • How to update elements in arrays of maps in Firestore?
  • How to update array elements in Firestore with Android?
  • How to update arrayList in cloud firestore in android

Problem :

I’m trying to update some data in my firestore database and the data inside is Map<String,List<String>> in other words, a map of lists.
so when I’m trying to update a list inside the map, it casting the list to a map.

my code:

  Calendar calendar = Calendar.getInstance();
  String currentDate =  DateFormat.getDateInstance().format(calendar.getTime());
  DocumentReference docRef = db.collection("incomes").
     document(firebaseAuth.getCurrentUser().getUid());
 docRef.update(
   index + ".0", incomeTitleEt.getText().toString(),
   index + ".1", incomeAmountEt.getText().toString(),
   Integer.toString(index)+".2",currentDate
 ).addOnCompleteListener(new OnCompleteListener<Void>() {
   @Override
   public void onComplete(@NonNull Task<Void> task) {
   }
});

Comments

Comment posted by almogbb

You mean take it from the database, then update it and send it back to the database?

Comment posted by Frank van Puffelen

Yes, that’s what it takes to update an item in the databae.

READ  [FIXED] android - CameraPreview Ionic Cordova error 'plugin_not_installed', but the plugin IS installed | Angular 8
Powered by Inline Related Posts

Android Tags:android, database, firebase, google-cloud-firestore

Post navigation

Previous Post: [FIXED] How to get Firebase auth token in Android login
Next Post: [FIXED] android – what should be the input and output forom of variables for float object detection model

Related Posts

[FIXED] How to change the color of element in SVG Image in Android Android
[FIXED] android – replace fragment happens just after program finish Android
[FIXED] android – Flutter app crashes when resuming to type Android
[FIXED] android – Simple yet tricky layout using ConstraintLayout Android
[FIXED] android – How to send image as a ‘File’ inside of http post body Android
[FIXED] android – Filtering results with GeoFirestore and Firestore Android

Archives

  • April 2023
  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuándo
  • ¿Cuántas
  • ¿Cuánto
  • ¿Qué
  • Android
  • Are
  • At
  • C'est
  • Can
  • Comment
  • Did
  • Do
  • Does
  • Est-ce
  • Est-il
  • For
  • Has
  • Hat
  • How
  • In
  • Is
  • Ist
  • Kann
  • Où
  • Pourquoi
  • Quand
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welchen
  • Welcher
  • Welches
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Who's
  • Why
  • Wie
  • Will
  • Wird
  • Wo
  • Woher
  • you can create a selvedge edge: You can make the edges of garter stitch more smooth by slipping the first stitch of every row.2022-02-04
  • you really only need to know two patterns: garter stitch

Recent Posts

  • Can Vicks humidifier be used without filter?
  • What color is Spanish green?
  • How old is Jamie in The War That Saved My Life?
  • When should I use scalp massager for hair growth?
  • Can I put polyurethane over liming wax?

Recent Comments

No comments to show.

Copyright © 2023 Snappy1.

Powered by PressBook Grid Dark theme