Answer the question
In order to leave comments, you need to log in
How to properly design MongoDB?
Colleagues, good day!
The question arose about designing a database - a list of countries and cities. It is not possible to use ready-made APIs, because the base will be collected from a bunch of different sources (api transport companies).
To solve the problem, there is a desire to use MongoDB with the content of subcollections.
Example:
{
country: "Россия",
regions: [
{
region: "Тюменская область",
cities: [
{city: "Тюмень", .....},
....
]
}
]
}
Answer the question
In order to leave comments, you need to log in
In such nested attachments, then search by indexes does not work, but for the first time.
It is necessary to "design" so that there are fewer attachments, but there are sending fields. All separate collections.
Well, like a collection (model) City
{
name: String,
region: String,
country: String
}
And then, to select all the cities of Chukotka located in the USA, you can simply query:
City
.find()
.where('region', 'Чукотка')
.where('country', 'США')
.exec(...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question