Answer the question
In order to leave comments, you need to log in
Data storage: regular object or key as value?
Good afternoon.
I use a document-oriented database (mongo).
An example object structure:
contries = [
{
name: "Russia",
cities: [ 'Moscow', 'Spb' ]
},
{
name: "Mongolia",
cities: ['Ulaahn', 'Hovd']
}
]
contries = [
{ "Russia" : [ 'Moscow', 'Spb' ] },
{ "Mongolia" : ['Ulaahn', 'Hovd'] }
]
Answer the question
In order to leave comments, you need to log in
A document, in the context of Mongi, is a JSON object, which in turn is a key-value set. In the first example you gave, key is name and cities, and value is a string with the name of the country and an array of cities. There are no keys in the second option, which means that it will not work db.collection.find({ country: "Russia" })
and you will have to use full-text search. Decide for yourself here.
And by the way: co u ntries.
Usually it is more convenient that the keys are fixed - no need to guess / iterate over to get the value.
The problem may arise if you add another country to each element in the future, or the like.
This will (almost) not save memory. There will be no storage issues.
If it is not planned to expand and fits well with current requests, then no problem.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question