【问题】
Imagine you have a collection for posts, and each of these posts has the attribute userid: ObjectId( ), where ObjectID is referencing a document in the Users collection.
How would you go about retrieving the user information (in this case, the user document might contain a username, email, full name, etc) as part of a query on the Posts collection?
【回答】
用 Mongodb 是不支持 join 查询的, 要多次查询很不方便。可以考虑配合 mongodb 使用的本身有计算能力的工具,比如使用 SPL。举例说明:
通过 employee 文档和 seller 文档查询 employee.state 为 California 的 sales orders。