我是mongodb的新手。我需要通过连接两个集合来进行查询。
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;
我需要使用mongodb的java api来执行它。我知道mongodb不支持joins。我有一个想法要实现,但我不知道这是不是最好的。
想法:
通过拆分来执行两个查询。(从用户集合中检索uuid并检查评论集合的uuid )
有没有其他的想法来实现它?谁能给我发送mongodb java代码来执行这个查询,方法是将其分成两个查询并获得结果。
发布于 2012-08-30 10:29:28
for each retrieved user
find every comments for this user
或者使用DBRef
for each comment
DBRef::fetch(comment.user)
https://stackoverflow.com/questions/12194626
复制