1

My structure looks like this:

Firestore
--- collection: Restaurant
------- field: Managers (of type map)
------------ john.appleseed : 110909
------------ sarah.malak : 890758

I cannot use the use the arrayRemove because then it removes all of the entries. And I cannot use the dot notation because my strings contain dots and those are not being recognized hence not deleted.

BVB09
  • 805
  • 9
  • 19
  • Instead of describing how your database looks like, please add a screenshot of it. Besides that, you are trying to remove an entry within that `Managers` map or the entire document? – Alex Mamo Mar 09 '20 at 09:43

2 Answers2

0

There are some ways that you can achieve deleting multiples values from your Collection, using id as to check which documents will be deleted. The below code - based on the post from the Community here - demonstrates an example of deleting documents per id of the Managers.

WriteBatch batch = db.batch();

for (String id : idsList) {
    DocumentReference ref = db.collection("Managers").document(id);
    batch.delete(ref);
}

batch.commit();

I would recommend you to check the above post and this other one below, for more information on how to achieve the deletion of multiple documents.

Besides that, there is the additional information on the official documentation Delete data from Cloud Firestore, in case you want to check further details.

Let me know if the information helped you!

gso_gabriel
  • 4,199
  • 1
  • 10
  • 22
0

The following works on another language. Using the documentation, here is the port to Java:

DocumentReference ref = db.collection("Restaurant").document("Managers");

Map<String, Object> updates = new HashMap<String, Object>();
updates.put("john.appleseed", FieldValue.delete());

ref.update(changes).addOnCompleteListener(new OnCompleteListener<Void>() {});

Hopefully this is not too far off (I cannot test with Java).

Eric Platon
  • 9,819
  • 6
  • 41
  • 48