I have user table and this code.
getOnline code and connected button
var onlineStatus = firebase.database().ref("users/" + firebase.auth().currentUser.uid + "/online");
onlineStatus.set(1);
and
var dbUser = firebase.database();
var refUser = dbUser.ref("users");
refUser.orderByChild("online").equalTo(1).on("value", function(Data){
console.log(Data.val(), Data.key);
});
I can already see online=1 users, but I want to randomly get 1 user who has the online = 1.
How can I do this?
Update
I want to build randomly chat. people will match according to the criteria. like Tinder App. Think about it, there is a page and button. When the user presses the button, it will match any online user. and chatting.
firebase users;
users
VIkvYAtLHxNqAwd722oKenriM7PJz2
email: "mail@hotmail.com"
online: 1
profile_picture:"https://scontent.xx.fbcdn.net"
username: "John Snow"
DIkvYAtLHxNqAwd722oKenriM7PJz2
email: "mail2@hotmail.com"
online: 1
profile_picture:"https://scontent.xx.fbcdn.net"
username: "Jane Snow"