Map/reduce on multiple values from single type of document

174 views Asked by At

To set the scene.

I currently have three types of documents. (Stripped out properties not needed for the example).

User { Id }
Location { Id }
Excursion { UserId, LocationId }

What I'm trying to achieve is to M/R some statistics about the location (Number of visitors and Number of visits).

Question 1: Is the data structure a good one? Should I use one M/R for Number of visitors and another one for Number of visits?

I'm trying to achieve this one query, using a map on documents of type "Excursion".

In theory there could be added data to an excursion, for example length in minutes, that could be included in statistics. There could also be an addition on Location itself, say for example a rating that could be included in statistics.

Question 2: It feels like I'm approaching this incorrectly, trying to make a Statistics View for everything in one go?

Any thoughts would be helpful, thanks in advance!

1

There are 1 answers

2
smathy On BEST ANSWER

Is the data structure a good one?

Without knowing a lot more it's hard to say, but your examples definitely look very much like you're trying to just map your Relational DB style tables onto a document database, which generally does not lead to good data structure.

Should I use one M/R for Number of visitors and another one for Number of visits?

Yes, although you'll probably use the same reduce function for both, in fact the built in _count function will work.

Definitely it sounds like you're approaching this incorrectly, don't worry too much about consolidating views - it's not something you should be striving for.