mongodb的:
#Authors collection
db.authors.insert({name: 'Kobo', birthday: '1860', country: 'jp', tags: ['japan', 'avant-garde', 'screen', 'Akutagawa Prize']})
db.authors.insert({name: 'Sartr', birthday: '1905', country: 'fr', tags: [...]})
db.authors.insert({name: 'Braun', birthday: '1913', country: 'us', tags: [...]}
...
#Books collection
db.books.insert({title: 'book1', author: 'Kobo', year :''});
db.books.insert({title: 'book2', author: 'Sartr', year :''});
db.books.insert({title: 'book3', author: 'author', year :''});
...
Autor标签会定期添加到集合作者。 在这个问题中不考虑使用书签。
需要查找作者具有特定标签的所有图书。如前卫#39; 这样做最有效的方法是什么? 如何在pymongo中做到这一点?
答案 0 :(得分:-1)
MongoDB不支持联接。因此,使用您拥有的数据模型,您必须将其分解为2个查询:
如果您的数据是使用嵌入式文档建模的,即在authors
内嵌入books
或其他方式,则可以在一次查询中获得结果。