Skip to content

Instantly share code, notes, and snippets.

@abinavseelan
Created December 14, 2017 19:34
Show Gist options
  • Select an option

  • Save abinavseelan/1eb4b0776c1a08a070d55a58f36a4d73 to your computer and use it in GitHub Desktop.

Select an option

Save abinavseelan/1eb4b0776c1a08a070d55a58f36a4d73 to your computer and use it in GitHub Desktop.
Create key-value pair on Real Time Database
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