This answer will greatly help.
let chatRef = db
.collection("chat_event").document("chat1")
.collection("messages").document("message1");
If you don't want to hardcode the parent document's id or if you want a firestore generated id. Then get the id first from firestore's createId()
function.
let chatEventId = db.createId();
let chatRef = db
.collection("chat_event").document(chatEventId)
.collection("messages").document("message1");
You could still use auto-generated id for the subcollection's document:
let chatEventId = db.createId();
let messageId = db.createId();
let chatRef = db
.collection("chat_event").document(chatEventId)
.collection("messages").document(messageId);
Note that firestore's autogenerated IDs are entirely random and consequently the documents are not stored in any chronological order. If you will in anyway need some ordering, you could add timestamps to those documents either when you insert data or you update the document with the timestamp info.
docRef.update({
timestamp: firebase.firestore.FieldValue.serverTimestamp()
});
With that, you can order chronologically both in the console and in your own queries.
Check out this answer for more information on auto-generating IDs