0

According to this post,aggregation is much better in performance than mapReduce,

but as far as I know aggregation can't do join-like operation which involve multiple collections, which is required for example when you want to sort the payment by the user's age,which are in two difference collections.

Is there any good solution to use aggregation in these situations?

There're many,many such requirements in my project, so I want to know what's the current best practice in doing this, or how bad the mapReduce performance is in newest mongodb.

Thanks in advance!

Community
  • 1
  • 1

1 Answers1

1

Short answer: There is no good solution.

If you need joins, you shouldn't be using Mongo. It explicitly doesn't provide for joins; you're supposed to address that via your data design by denormalizing data into your documents at write-time in order to make it queryable in the fashion you need down the road. In your example, you would denormalize the user's age into the payment document when you create it and associate it with your user record. This would let you perform the expected queries.

Mongo is not very good at ad hoc queries on highly normalized data - it assumes aggressive denormalization and foreknowledge of the sorts of queries you're going to want to be doing. If you need ad hoc queries on highly normalized data, you should probably look into using a relational database.

Chris Heald
  • 61,439
  • 10
  • 123
  • 137
  • To sort by age is my contrived example, in the real case I need to sort by the activeness which is calculated dynamically on a daily basis, so I want some other solution than denormalizing.Thank you all the same:) – user2559257 Jul 08 '13 at 03:33
  • You're going to be stuck with map-reduce then - that's more or less the classic use case for it in a Mongo context. You can save and denormalize the results of those map-reduce runs, though, so even if they aren't fast they won't be a throttling factor in your application. – Chris Heald Jul 08 '13 at 03:35