Reputation: 341
I'm using MongoDB and Node.js. Let's say we have two users:
{
"name": "user1",
"email": "[email protected]",
"pairedWith": "[email protected]",
"paired": false,
}
and
{
"name": "user2",
"email": "[email protected]",
"pairedWith": "[email protected]",
"paired": false,
}
They can pair with each other by searching for the correct email address. After both users searched for the email and paired with each other, I want the paired
field to become true
automatically. Only after both users have paired. Of course here user1 must be paired with user2, and user2 must be paired with user1 because they specifically wanted that.
So how do I tell MongoDB to update paired to true automatically once 2 users are paired? Based on this true value, I will display something for both of them, but until it's not true, I can't.
Upvotes: 0
Views: 138
Reputation: 13
you can add an additional field for entered_correct email. So, if user1 enters correct email set it to true. now, when user2 enters correct email for user1 set it to true.
both times check in another user's document if entered_correct is true there. When both documents have entered_correct true, set paired to true in both of them.
Upvotes: 1