Created
December 14, 2017 19:34
-
-
Save abinavseelan/1eb4b0776c1a08a070d55a58f36a4d73 to your computer and use it in GitHub Desktop.
Create key-value pair on Real Time Database
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const firestoreDb = firebase.firestore(); | |
| const oldRealTimeDb = firebase.database(); | |
| const usersRef = firestoreDb.collection('users'); // Get a reference to the Users collection; | |
| const onlineRef = oldRealTimeDb.ref('.info/connected'); // Get a reference to the list of connections | |
| onlineRef.on('value', snapshot => { | |
| // Set the Firestore User's online status to true | |
| usersRef | |
| .doc(userId) | |
| .set({ | |
| online: true, | |
| }, { merge: true}); | |
| // Let's also create a key in our real-time database | |
| // The value is set to 'online' | |
| oldRealTimeDb.ref(`/status/${userId}`).set('online'); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment