我是mongodb的新手。我需要通过joinin两个集合进行查询。
comments
{ uid:12345, pid:444, comment="blah" }
{ uid:12345, pid:888, comment="asdf" }
{ uid:99999, pid:444, comment="qwer" }
users
{ uid:12345, name:"john" }
{ uid:99999, name:"mia" }
query: Select c.pid, c.comment from comments c, users u uwhere c.uid = u.uid;
我需要使用java api为mongodb执行它。我知道mongodb不支持连接。我有一个想法可以实现,但我不知道它是否是最好的。
主意:
通过拆分执行两个查询。 (从用户集合中检索uuid并检查注释集合的uuid)
实现它的任何其他想法?任何人都可以通过分成两个查询并获得结果来发送mongodb java代码来执行此查询。
答案 0 :(得分:0)
for each retrieved user
find every comments for this user
或使用DBRef
for each comment
DBRef::fetch(comment.user)