besides emit() in map(), can I simply omit this map-reduce cycle?

34 views
Skip to first unread message

λq

unread,
Jul 11, 2011, 11:57:14 PM7/11/11
to mongod...@googlegroups.com
Hi guys,

I knew that mapReduce() has a query parameter, but in my case, 


{
  'user': user1,
  'top-list': [
    {'score': score1, 'date': date1, 'app': app1},
    {'score': score4, 'date': date4, 'app': app4},
    {'score': score3, 'date': date3, 'app': app3},
  ]
}

I want to use mapReduce() to find the history position change of a particular my_app

the query parameter can do the job, but IMHO it looks redundant because when doing the map(), I have to iterate the 'top-list' array again. 

Is there something like pass() or omit() besides the standard emit() in map function? So mongodb could just skip this round of map-reduce and continue next?

Eliot Horowitz

unread,
Jul 12, 2011, 12:06:01 AM7/12/11
to mongod...@googlegroups.com
I'm a bit confused by what you mean.
Is that a sample document that's in the collection?

What would the output look like?

2011/7/11 λq <lam...@gmail.com>:

> --
> You received this message because you are subscribed to the Google Groups
> "mongodb-user" group.
> To post to this group, send email to mongod...@googlegroups.com.
> To unsubscribe from this group, send email to
> mongodb-user...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/mongodb-user?hl=en.
>

λq

unread,
Jul 12, 2011, 12:16:21 AM7/12/11
to mongod...@googlegroups.com

{
  'user': user1,
  'day': '2011-07-09'
  'top-list': [
    {'score': score1, 'date': date1, 'app': app1},
    {'score': score2, 'date': date2, 'app': app2},
    {'score': score3, 'date': date3, 'app': app3},
  ]
},
{
  'user': user1,
  'day': '2011-07-10'
  'top-list': [
    {'score': score1, 'date': date1, 'app': app1},
    {'score': score3, 'date': date3, 'app': app3},
    {'score': score4, 'date': date4, 'app': app4},
  ]
},
{
  'user': user1,
  'day': '2011-07-11'
  'top-list': [
    {'score': score3, 'date': date3, 'app': app3},
    {'score': score4, 'date': date4, 'app': app4},
    {'score': score2, 'date': date2, 'app': app2},
  ]
},


Given app3, return a result like:

{'2011-07-09': 3, '2011-07-10': 2, '2011-07-11': 1}

app3 is at rank #3 place in 2011-07-09, raised to #1 and #1 in the following days.

But in the collection, app3 is out of the 'top-list'array, so I do not want the mapReduce() to process this document, yes just a 'query' parameter for mapReduce() could filter that out, but since I already need to iterate the whole 'top-list' array in the map() function, I think I don't need 'query' parameter?

So can I skip a number of documents for a map() ?

2011/7/12 Eliot Horowitz <elioth...@gmail.com>

Eliot Horowitz

unread,
Jul 12, 2011, 12:19:21 AM7/12/11
to mongod...@googlegroups.com
The query would still be helpful if there are documents that don't
have app3 at all.
If all do, then the query isn't needed.

2011/7/12 λq <lam...@gmail.com>:

λq

unread,
Jul 12, 2011, 12:24:29 AM7/12/11
to mongod...@googlegroups.com
Yes the 'query' parameter is helpful, but I think 'query' needs to lookup the whole 'top-list' array or index, then I look them up again because I need to find its position?

Some performance is wrong here. (I hope mongodb could just get the position of the element in the array if there is already a 'query' parameter.)

Eliot Horowitz

unread,
Jul 12, 2011, 1:11:33 AM7/12/11
to mongod...@googlegroups.com
Correct - mongo won't do that for you.
You can open a feature request @ http://jira.mongodb.org

2011/7/12 λq <lam...@gmail.com>:

Reply all
Reply to author
Forward
0 new messages