Connect two random users from Database












0















I’m trying to create an app where I need to match two random users from my Firebase Database. The problem I have is that I‘m not sure how to connect every user of the database to random pairs:
As far as I thought the user might press a button to signal that he‘s ready, so a child of his UID like 'searching' turns from false to true. By receiving a DataSnapshot the user can see if another user is searching too. Then I thought of turning the 'searching' state to false for both users and create a new UniqueID to connect them.



But like that it‘s thought pretty short, I think and would cause some problems. Can anyone give me a hint on how to organize that searching process?










share|improve this question

























  • Hey @user9582784 if my answer helped you solve your problem, then do mark it as correct by clicking on tick mark V type button next to to it, and upvote it. This helps future readers of this question and I'd appreciate that too. Cheers! :)

    – PradyumanDixit
    Nov 27 '18 at 3:47











  • Yeah, I won‘t forget it, I didn‘t have enough time to spend it on that, so I‘m still checking if everything works for me, then I‘ll immediately mark it as correct! :)

    – user9582784
    Nov 27 '18 at 10:12











  • Isn‘t it possible that two user get a snapshot at the same time and may randomly choose the same other user? I guess it‘s a quite low danger, but is there a way to avoid that?

    – user9582784
    Nov 27 '18 at 20:33











  • In the algorithm I have told you in the answer, we follow just one thing, we find people who are searching and then just randomly get a number, from the number of id's we have. In random numbers, there's a possibility that two people may choose one another, but that's what it is, and nothing I think, can be done about it, also random should mean, not in our hands to control and it is that.

    – PradyumanDixit
    Nov 28 '18 at 4:06











  • Okay, that sounds right. So do you think that case would be negligible?

    – user9582784
    Nov 28 '18 at 19:24
















0















I’m trying to create an app where I need to match two random users from my Firebase Database. The problem I have is that I‘m not sure how to connect every user of the database to random pairs:
As far as I thought the user might press a button to signal that he‘s ready, so a child of his UID like 'searching' turns from false to true. By receiving a DataSnapshot the user can see if another user is searching too. Then I thought of turning the 'searching' state to false for both users and create a new UniqueID to connect them.



But like that it‘s thought pretty short, I think and would cause some problems. Can anyone give me a hint on how to organize that searching process?










share|improve this question

























  • Hey @user9582784 if my answer helped you solve your problem, then do mark it as correct by clicking on tick mark V type button next to to it, and upvote it. This helps future readers of this question and I'd appreciate that too. Cheers! :)

    – PradyumanDixit
    Nov 27 '18 at 3:47











  • Yeah, I won‘t forget it, I didn‘t have enough time to spend it on that, so I‘m still checking if everything works for me, then I‘ll immediately mark it as correct! :)

    – user9582784
    Nov 27 '18 at 10:12











  • Isn‘t it possible that two user get a snapshot at the same time and may randomly choose the same other user? I guess it‘s a quite low danger, but is there a way to avoid that?

    – user9582784
    Nov 27 '18 at 20:33











  • In the algorithm I have told you in the answer, we follow just one thing, we find people who are searching and then just randomly get a number, from the number of id's we have. In random numbers, there's a possibility that two people may choose one another, but that's what it is, and nothing I think, can be done about it, also random should mean, not in our hands to control and it is that.

    – PradyumanDixit
    Nov 28 '18 at 4:06











  • Okay, that sounds right. So do you think that case would be negligible?

    – user9582784
    Nov 28 '18 at 19:24














0












0








0








I’m trying to create an app where I need to match two random users from my Firebase Database. The problem I have is that I‘m not sure how to connect every user of the database to random pairs:
As far as I thought the user might press a button to signal that he‘s ready, so a child of his UID like 'searching' turns from false to true. By receiving a DataSnapshot the user can see if another user is searching too. Then I thought of turning the 'searching' state to false for both users and create a new UniqueID to connect them.



But like that it‘s thought pretty short, I think and would cause some problems. Can anyone give me a hint on how to organize that searching process?










share|improve this question
















I’m trying to create an app where I need to match two random users from my Firebase Database. The problem I have is that I‘m not sure how to connect every user of the database to random pairs:
As far as I thought the user might press a button to signal that he‘s ready, so a child of his UID like 'searching' turns from false to true. By receiving a DataSnapshot the user can see if another user is searching too. Then I thought of turning the 'searching' state to false for both users and create a new UniqueID to connect them.



But like that it‘s thought pretty short, I think and would cause some problems. Can anyone give me a hint on how to organize that searching process?







firebase firebase-realtime-database






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 25 '18 at 15:18









Frank van Puffelen

240k29384411




240k29384411










asked Nov 25 '18 at 11:40









user9582784user9582784

355




355













  • Hey @user9582784 if my answer helped you solve your problem, then do mark it as correct by clicking on tick mark V type button next to to it, and upvote it. This helps future readers of this question and I'd appreciate that too. Cheers! :)

    – PradyumanDixit
    Nov 27 '18 at 3:47











  • Yeah, I won‘t forget it, I didn‘t have enough time to spend it on that, so I‘m still checking if everything works for me, then I‘ll immediately mark it as correct! :)

    – user9582784
    Nov 27 '18 at 10:12











  • Isn‘t it possible that two user get a snapshot at the same time and may randomly choose the same other user? I guess it‘s a quite low danger, but is there a way to avoid that?

    – user9582784
    Nov 27 '18 at 20:33











  • In the algorithm I have told you in the answer, we follow just one thing, we find people who are searching and then just randomly get a number, from the number of id's we have. In random numbers, there's a possibility that two people may choose one another, but that's what it is, and nothing I think, can be done about it, also random should mean, not in our hands to control and it is that.

    – PradyumanDixit
    Nov 28 '18 at 4:06











  • Okay, that sounds right. So do you think that case would be negligible?

    – user9582784
    Nov 28 '18 at 19:24



















  • Hey @user9582784 if my answer helped you solve your problem, then do mark it as correct by clicking on tick mark V type button next to to it, and upvote it. This helps future readers of this question and I'd appreciate that too. Cheers! :)

    – PradyumanDixit
    Nov 27 '18 at 3:47











  • Yeah, I won‘t forget it, I didn‘t have enough time to spend it on that, so I‘m still checking if everything works for me, then I‘ll immediately mark it as correct! :)

    – user9582784
    Nov 27 '18 at 10:12











  • Isn‘t it possible that two user get a snapshot at the same time and may randomly choose the same other user? I guess it‘s a quite low danger, but is there a way to avoid that?

    – user9582784
    Nov 27 '18 at 20:33











  • In the algorithm I have told you in the answer, we follow just one thing, we find people who are searching and then just randomly get a number, from the number of id's we have. In random numbers, there's a possibility that two people may choose one another, but that's what it is, and nothing I think, can be done about it, also random should mean, not in our hands to control and it is that.

    – PradyumanDixit
    Nov 28 '18 at 4:06











  • Okay, that sounds right. So do you think that case would be negligible?

    – user9582784
    Nov 28 '18 at 19:24

















Hey @user9582784 if my answer helped you solve your problem, then do mark it as correct by clicking on tick mark V type button next to to it, and upvote it. This helps future readers of this question and I'd appreciate that too. Cheers! :)

– PradyumanDixit
Nov 27 '18 at 3:47





Hey @user9582784 if my answer helped you solve your problem, then do mark it as correct by clicking on tick mark V type button next to to it, and upvote it. This helps future readers of this question and I'd appreciate that too. Cheers! :)

– PradyumanDixit
Nov 27 '18 at 3:47













Yeah, I won‘t forget it, I didn‘t have enough time to spend it on that, so I‘m still checking if everything works for me, then I‘ll immediately mark it as correct! :)

– user9582784
Nov 27 '18 at 10:12





Yeah, I won‘t forget it, I didn‘t have enough time to spend it on that, so I‘m still checking if everything works for me, then I‘ll immediately mark it as correct! :)

– user9582784
Nov 27 '18 at 10:12













Isn‘t it possible that two user get a snapshot at the same time and may randomly choose the same other user? I guess it‘s a quite low danger, but is there a way to avoid that?

– user9582784
Nov 27 '18 at 20:33





Isn‘t it possible that two user get a snapshot at the same time and may randomly choose the same other user? I guess it‘s a quite low danger, but is there a way to avoid that?

– user9582784
Nov 27 '18 at 20:33













In the algorithm I have told you in the answer, we follow just one thing, we find people who are searching and then just randomly get a number, from the number of id's we have. In random numbers, there's a possibility that two people may choose one another, but that's what it is, and nothing I think, can be done about it, also random should mean, not in our hands to control and it is that.

– PradyumanDixit
Nov 28 '18 at 4:06





In the algorithm I have told you in the answer, we follow just one thing, we find people who are searching and then just randomly get a number, from the number of id's we have. In random numbers, there's a possibility that two people may choose one another, but that's what it is, and nothing I think, can be done about it, also random should mean, not in our hands to control and it is that.

– PradyumanDixit
Nov 28 '18 at 4:06













Okay, that sounds right. So do you think that case would be negligible?

– user9582784
Nov 28 '18 at 19:24





Okay, that sounds right. So do you think that case would be negligible?

– user9582784
Nov 28 '18 at 19:24












1 Answer
1






active

oldest

votes


















2














Actually using a special node like searching and setting it to true and false will be a good idea.



You can use orderByChild() to order all the users with searching node set to true and get the uid of any of those users.



To make the process random you could make a call to users, take the ids given back to you, and pick one at random with a basic random number.



If after making a call to users you have 10 user ids in an array you would want to get a random number between 0-9 and then make a call to firebase with the userId.



I don't believe Firebase has any built in code for this. So this would be the best thing you can do to achieve this feature in your app.



To give a basic idea, your database structure should look something like this:



--rootNode
|
|
-- uid1
| |
| - searching
| - other Fields
|
-- uid2

.
.
.





share|improve this answer
























  • Okay, thank you very much so far! I‘m gonna try it like this and let you know if it worked for me :)

    – user9582784
    Nov 25 '18 at 12:57











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53467067%2fconnect-two-random-users-from-database%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














Actually using a special node like searching and setting it to true and false will be a good idea.



You can use orderByChild() to order all the users with searching node set to true and get the uid of any of those users.



To make the process random you could make a call to users, take the ids given back to you, and pick one at random with a basic random number.



If after making a call to users you have 10 user ids in an array you would want to get a random number between 0-9 and then make a call to firebase with the userId.



I don't believe Firebase has any built in code for this. So this would be the best thing you can do to achieve this feature in your app.



To give a basic idea, your database structure should look something like this:



--rootNode
|
|
-- uid1
| |
| - searching
| - other Fields
|
-- uid2

.
.
.





share|improve this answer
























  • Okay, thank you very much so far! I‘m gonna try it like this and let you know if it worked for me :)

    – user9582784
    Nov 25 '18 at 12:57
















2














Actually using a special node like searching and setting it to true and false will be a good idea.



You can use orderByChild() to order all the users with searching node set to true and get the uid of any of those users.



To make the process random you could make a call to users, take the ids given back to you, and pick one at random with a basic random number.



If after making a call to users you have 10 user ids in an array you would want to get a random number between 0-9 and then make a call to firebase with the userId.



I don't believe Firebase has any built in code for this. So this would be the best thing you can do to achieve this feature in your app.



To give a basic idea, your database structure should look something like this:



--rootNode
|
|
-- uid1
| |
| - searching
| - other Fields
|
-- uid2

.
.
.





share|improve this answer
























  • Okay, thank you very much so far! I‘m gonna try it like this and let you know if it worked for me :)

    – user9582784
    Nov 25 '18 at 12:57














2












2








2







Actually using a special node like searching and setting it to true and false will be a good idea.



You can use orderByChild() to order all the users with searching node set to true and get the uid of any of those users.



To make the process random you could make a call to users, take the ids given back to you, and pick one at random with a basic random number.



If after making a call to users you have 10 user ids in an array you would want to get a random number between 0-9 and then make a call to firebase with the userId.



I don't believe Firebase has any built in code for this. So this would be the best thing you can do to achieve this feature in your app.



To give a basic idea, your database structure should look something like this:



--rootNode
|
|
-- uid1
| |
| - searching
| - other Fields
|
-- uid2

.
.
.





share|improve this answer













Actually using a special node like searching and setting it to true and false will be a good idea.



You can use orderByChild() to order all the users with searching node set to true and get the uid of any of those users.



To make the process random you could make a call to users, take the ids given back to you, and pick one at random with a basic random number.



If after making a call to users you have 10 user ids in an array you would want to get a random number between 0-9 and then make a call to firebase with the userId.



I don't believe Firebase has any built in code for this. So this would be the best thing you can do to achieve this feature in your app.



To give a basic idea, your database structure should look something like this:



--rootNode
|
|
-- uid1
| |
| - searching
| - other Fields
|
-- uid2

.
.
.






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 25 '18 at 11:48









PradyumanDixitPradyumanDixit

2,1872820




2,1872820













  • Okay, thank you very much so far! I‘m gonna try it like this and let you know if it worked for me :)

    – user9582784
    Nov 25 '18 at 12:57



















  • Okay, thank you very much so far! I‘m gonna try it like this and let you know if it worked for me :)

    – user9582784
    Nov 25 '18 at 12:57

















Okay, thank you very much so far! I‘m gonna try it like this and let you know if it worked for me :)

– user9582784
Nov 25 '18 at 12:57





Okay, thank you very much so far! I‘m gonna try it like this and let you know if it worked for me :)

– user9582784
Nov 25 '18 at 12:57




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53467067%2fconnect-two-random-users-from-database%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Wiesbaden

Marschland

Dieringhausen