Advertisements
//Getting instance FirebaseFirestore db = FirebaseFirestore.getInstance(); //Creating Map for the values we want to store Map<String ,String> data = new HashMap<>(); data.put("username","waqas"); //Getting Reference to "users" collection //REMEMBER: at this point, no collection will be created CollectionReference collectionReference = db.collection("users"); //Getting reference to "new doc" document //REMEMBER: at this point, no document will be created either DocumentReference documentReference = collectionReference.document("new doc"); //Writing data //REMEMBER: here both collection and document will be created and fields and values we created in hash will be stored to that document. documentReference.set(data);