Question is about best way to handle data.
Let's assume we have such key -> value data:
"user@gmail.com": { "name": "John",
"age": 20,
"job": "developer",
"favourite_food": ['taco', 'steak']
//...etc
}
//...etc
There is a lot of data for users with key "email", like a million.
And usually I had to search users by their email.
But today my boss came up to me and said he want to search users by their names and of course keep possibility to search by email. On the other day he said he want my program to realize search by age and so on.
My first thought was to iterate over data with, for example, this php code:
foreach($email as $data){
foreach($data as $k => $v){
if($v == 'search value'){
return $email;
}
}
}
But this solution is not good for big amount of data.
My second idea was to iterate over first data and create for each email own table to make it look like this:
$a = "user@gmail.com": {//all data}
$b = "John" : {//all data including email}
$c = "developer":{//all other data}
// and so on
But my users getting older with time, so I have to update user age every time the data in my main object changes.
So, my question is, what is the best way to implement such logic using any programming language?
Some notes:
It had to be done by using programming language without touching MySQL or any other DB.