How to create sub collection to firebase firestore document

Viewed 77

Is there a way to create sub collection after set() method like shown below?

enter image description here

                    CollectionReference ref1 =
                        FirebaseFirestore.instance.collection('chatrooms');
                    await ref1
                        .doc(chatroom)
                        .set({"chatid": chatroom})
                        .collection('messages')
                        .add({"message": _message.text});
1 Answers
    CollectionReference ref1 =
    FirebaseFirestore.instance.collection('chatrooms');
await ref1.doc('doc').set({"chatid": chatroom});
await ref1
    .doc('doc')
    .collection('messages')
    .add({"message": _message.text});

U can split it like this

Related