I'm trying to understand how to set up basic relations in mongoDB. I've read a bit about it in the documentation but it's a little terse.
This should be pretty simple: I'm trying to log a list of impressions and the users who are responsible for the impressions. Here's some examples of log documents:
{type: '1', userId:'xxx-12345'}
{type: '1', userId:'xxx-12345'}
{type: '1', userId:'xxx-12345'}
{type: '2', userId:'zzz-84638'}
{type: '2', userId:'xxx-12345'}
Here's an example of a user document:
{userId: 'xxx-12345', location: 'US'}
Is there a way to count the total number of documents which "belong" to a userId
of xxx-12345
, where type
is 1
?
In the above case, I'd want to see a result like { '1':3, '2':1 }
.
Also, is the above an acceptable way of creating the relationships?