Mongodb 查询多对多关系(引用)并显示所有数据
我一直在学习MongoDB,但由于有SQL背景,我真的很难处理涉及复杂数据的多对多关系 比如说我有过这样的经历Mongodb 查询多对多关系(引用)并显示所有数据,mongodb,express,mongodb-query,Mongodb,Express,Mongodb Query,我一直在学习MongoDB,但由于有SQL背景,我真的很难处理涉及复杂数据的多对多关系 比如说我有过这样的经历 Author { name: { type: String }, address: { type: string }, books: [{ book: type: ref: 'Books', author_comments: string }] } Books{ name: { type
Author {
name: { type: String },
address: { type: string },
books: [{
book: type: ref: 'Books',
author_comments: string
}]
}
Books{
name: { type: String },
completed { type: boolean }
}
我怎样才能查询author以获得给定的Authors id并返回类似的内容(显示所有的Authors数据+他们的书的所有名称以及Authors注释)
我一直在玩$lookup,但没法走远
非常感谢您的帮助
注意:使用express
{name: "authors name", address: "Authors address", books: [{name: "book name", author_comments: "Authors notes"},...]