Answer the question
In order to leave comments, you need to log in
How to select rows in Mongodb based on row values of a related collection?
MongoDB: #Collection
Authors
db.authors.insert({name: 'Chehov', birthday: '1860', country: 'ru'})
db.authors.insert({name: 'Sartr', birthday: '1905', country: 'fr'})
db.authors.insert({name: 'Braun', birthday: '1913', country: 'us'}
... #Book
Collection
db.books.insert({title: 'book1' , author: 'Chehov', year :''})
db.books.insert({title: 'book2', author: 'Sartr', year :''})
db.books.insert({title: 'book3' , author: 'Frauthor', year :''})
...
Let's assume that the Authors collection will be expanded with fields, that is, new fields will be added - some tags, for example.that the option to update the structure of the Books collection is not suitable.
What is the correct (productive) way to select all books that have country == 'fr' field, for example?
The question is about MongoDB, not about which database is better to use.
Answer the question
In order to leave comments, you need to log in
Here, probably, only "on the forehead", the first request is to get all the necessary authors, the second - to get books by these authors. It is also necessary that there were necessary indexes.
If the operation is frequent, then it is better to change the structure / make caching (for example, make books.author_country)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question