1let data = {
2 name: 'Los Angeles',
3 state: 'CA',
4 country: 'USA'
5};
6
7// Add a new document in collection "cities" with ID 'LA'
8let setDoc = db.collection('cities').doc('LA').set(data);
1Map<String, Object> city = new HashMap<>();
2city.put("name", "Los Angeles");
3city.put("state", "CA");
4city.put("country", "USA");
5
6db.collection("cities").document("LA")
7 .set(city)
8 .addOnSuccessListener(new OnSuccessListener<Void>() {
9 @Override
10 public void onSuccess(Void aVoid) {
11 Log.d(TAG, "DocumentSnapshot successfully written!");
12 }
13 })
14 .addOnFailureListener(new OnFailureListener() {
15 @Override
16 public void onFailure(@NonNull Exception e) {
17 Log.w(TAG, "Error writing document", e);
18 }
19 });
20
1var washingtonRef = db.collection("cities").doc("DC");
2// Atomically add a new region to the "regions" array field.
3washingtonRef.update({
4 regions: firebase.firestore.FieldValue.arrayUnion("greater_virginia")
5});
6// Atomically remove a region from the "regions" array field.
7washingtonRef.update({
8 regions: firebase.firestore.FieldValue.arrayRemove("east_coast")
9});