MIEP Family
0
Q:

document.set() firebasefirestore java

let data = {
  name: 'Los Angeles',
  state: 'CA',
  country: 'USA'
};

// Add a new document in collection "cities" with ID 'LA'
let setDoc = db.collection('cities').doc('LA').set(data);
3
Map<String, Object> city = new HashMap<>();
city.put("name", "Los Angeles");
city.put("state", "CA");
city.put("country", "USA");

db.collection("cities").document("LA")
        .set(city)
        .addOnSuccessListener(new OnSuccessListener<Void>() {
            @Override
            public void onSuccess(Void aVoid) {
                Log.d(TAG, "DocumentSnapshot successfully written!");
            }
        })
        .addOnFailureListener(new OnFailureListener() {
            @Override
            public void onFailure(@NonNull Exception e) {
                Log.w(TAG, "Error writing document", e);
            }
        });
0
// Create an initial document to update.var frankDocRef = db.collection("users").doc("frank");frankDocRef.set({    name: "Frank",    favorites: { food: "Pizza", color: "Blue", subject: "recess" },    age: 12});// To update age and favorite color:db.collection("users").doc("frank").update({    "age": 13,    "favorites.color": "Red"});
0
var washingtonRef = db.collection("cities").doc("DC");// Atomically add a new region to the "regions" array field.washingtonRef.update({    regions: firebase.firestore.FieldValue.arrayUnion("greater_virginia")});// Atomically remove a region from the "regions" array field.washingtonRef.update({    regions: firebase.firestore.FieldValue.arrayRemove("east_coast")});
0

New to Communities?

Join the community