title: How do I generate a unique key for each message in Realtime Database?
body: <p>I'm working on a simple group chat app. The realtime chatting will be done through Firebase Realtime Database and then after a while the messages will be moved to Firestore.</p>
  <p>This is the structure I'm thinking of for RTDB. The groupID will be the first node after the root DB node. The next child under the groupID node will be the message that each user sends. This node will contain the createdate, the actual message, the user's uid, and the user's username.</p>
  <p>However, I'm not sure how to generate a unique key in the place of MessageKey and MessageKey2 below. How do I generate something unique to insert in there?</p>
  <p><a href="https://i.stack.imgur.com/ykVBC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ykVBC.png" alt="enter image description here" /></a></p>
  <p>Note: I tried getting the key from <code>database.push()</code> but it gave me this: <a href="https://APPNAME-cf4da.firebaseio.com/-M_hwyb15XnNDjGDaO7X" rel="nofollow noreferrer">https://APPNAME-cf4da.firebaseio.com/-M_hwyb15XnNDjGDaO7X</a></p>
  <p>Would I just need to strip off that root node to use this as MessageKey?</p>