I am doing a collaborative note editing app which uses a NoSQL database (Firebase) in server side. Each user can sign up using their phone number or email. Currently, the user object has only four values: user_id, user_name, user_email, user_phone.

Any user can create a note by including people from his contacts even if they are not registered. If the person is not registered, an SMS/email will be sent to him that he was included and to sign up to participate.

The problem is that:

Each note object contain a list of users for it. Each user will have all fields including a randomly generated ID. If a person in that note sign up later, how can I link between that user and this note? The ID that a user will get when he sign up will be different from his ID in that earlier note. Currently the database consists of a users collection, notes collection.

One solution I came up with was:

Create a collection called pending_invites and add each non registered users from every note added (along with list of notes_id they are part of). When somebody signs up, compare him/her (using email or phone number) with each user in the pending_invites table and if found someone ,edit that user's ID (replace with ID he got during sign up) in those notes which he is a part of. But I feel this is not a good solution when there are many users.

Please provide a better solution if you have any ideas. Any changes in db structure are welcomed.

Assuming that there can only be one user with a particular email or phone number existing at once, you could simply look in the users table and find the one matching their information on signup, no?

So person A is signed-up and creates a note with person B's phone number who doesnt have an account. B receives an invite and joins, the link in the text contains an identifier that specifies that B's phone number was used for the referal.

  • In case of a referral link, it is OK. But if B didn't used that link and instead did the sign up separately, what will be the best way of connecting those users? – Tom Saju Aug 9 at 16:46
  • Technically you could perform the check either way, but that could open up to falsified linking, but it comes dow nto how much you trust your users; if you trust your users, say an internal system to your company, then performing the check at all times would work nicely. On the other hand though, saying in the email that they will only be added to the note that they were refered to automatically if they use that link would be a solution. In the event that they dont then they will be readded to the note upon a second referal, and the old account can be deleted as there is a duplicate – TurtleKwitty Aug 9 at 17:29
  • That is a good solution. Will check. – Tom Saju Aug 10 at 3:31

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.