I have a "Name" collection and when I am doing the POST call, I would search the database if there are any records which matches with SSN and will create a record with same name_id, basically to link the records with same SSN.
Also at the same time, I would be creating the NameDetails for every record.
The purpose of it is, when I do a GET call by SSN, it should fetch all records with matching SSN from Name collection and its respective NameDetails.
Currently, the Database design looks like below where name_id is a incremental sequence. But I do not want to use this as its a traditional way of doing in SQL.
I want to improve this without much impact on performance and also the code for create and fetch data from database.
Name Collection: { "_id" : ObjectId("5eda8c136d35bf3d5c59bda4"), "name_id" : 1, "name" : "John", "ssn" : "111-22-3333" } { "_id" : ObjectId("5eda8c136d35bf3d5c59bda5"), "name_id" : 1, "name" : "Fred", "ssn" : "111-22-3333" } { "_id" : ObjectId("5eda8c136d35bf3d5c59bda6"), "name_id" : 1, "name" : "Smith", "ssn" : "111-22-3333" }
NameDetails collection: { "_id" : ObjectId("5eda8c18b05c551ab88d28c7"), "name_id" : ObjectId("5eda8c136d35bf3d5c59bda4"), "name_details" : { "Case1" }} { "_id" : ObjectId("5eda8c18b05c551ab88d28c8"), "name_id" : ObjectId("5eda8c136d35bf3d5c59bda5"), "name_details" : { "Case2" }}