In currently running version of my application, I do not have any constraint on the uniqueness of user's phone number. It means, one phone number can be linked with multiple accounts. Only unique constrained is user's email id.
scenario 1: User registers with email Id and phone number => we create a new user record in Database respecting uniqueness of email. scenario 2: User registers with only number => we create a new user record in Database with a unique dummy-email that I generate.
In both of these scenarios , I maintain the uniqueness on email but ignore any such constraint on phone-number.
Now I need to maintain uniqueness property on both email and phone-number. So, I need to merge both the user accounts (dummy-email and real email) that share the same phone-number.
The problem is that both of these accounts can have multiple references at multiple places in Database. What should be the approach to merge two accounts together?
edit: I'm using MongoDB at backend. It generates '_id' field for every document and uses it as a primary key for that document. So, this '_id' field is served as a foreign key for that user document to rest of the database.
one sample document in users collections where user has a verified email =>
{
_id: ObjectId("5d443787f86f9a3dfa782a3c"),
name: 'user name',
email: 'VerifiedUserEmail@gmail.com',
phone_number: '1234567890'
}
another sample document in users collections where user is having duplicate phone-number =>
{
_id: ObjectId("5c9a1146c89b2d09740ccd17"),
name: 'dummy user name',
email: 'DummyUserEmail@dummy-emails.com',
phone_number: '1234567890'
}