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.