简体   繁体   中英

MongoDB PHP getting data from multi collections

I have 2 collections

  • Users - name,points,clan(ObjectID)
  • Clans - name

So I need to get Clans points with this logic:

Sum of all user points in the same clans, divide clan users count, group by clans, order by total points and limit 10. Shortly I need to get best 10 clans.

But I couldn't create query. Thanks for help.

You have to perform two queries and iterate through them in your code. There are no joins in MongoDB. Alternatively you could embed a Clan document in your User document so that you could query on just your user collection and get all the information you need.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM