Can I simplify this map/reduce ?

18 views
Skip to first unread message

Bdfy

unread,
Apr 13, 2012, 9:17:58 AM4/13/12
to mongodb-user
I have a map/reduce function on pymongo ( analog sql query: select
count( distinct on (ip,id )) ... ) . Can I simplify this map/reduce ?


map = Code(
"function () {"
"emit({ ip: this.ip, id: this.id }, {});"
"}"
)

reduce = Code("function (key, values) {""}")

results = self.mongo.map_reduce(map, reduce, "test", query =
{ .... }, "field" : "value" } )

count = 0
for result in results.find():
count = count + 1

print count


Sam Millman

unread,
Apr 13, 2012, 9:34:17 AM4/13/12
to mongod...@googlegroups.com
I dunno I'd say that's pretty darn simple already all your doing is picking a unique record out, saving that and then using your client code to get the count.

I'd say that's as simple as can get.



--
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.


Bdfy

unread,
Apr 13, 2012, 10:06:45 AM4/13/12
to mongodb-user
but list all valies in client ( for example 200 000 rows ) for one
result value - is it very "expensive" for time ?

On 13 апр, 17:34, Sam Millman <sam.mill...@gmail.com> wrote:
> I dunno I'd say that's pretty darn simple already all your doing is picking
> a unique record out, saving that and then using your client code to get the
> count.
>
> I'd say that's as simple as can get.
>

Sam Millman

unread,
Apr 13, 2012, 10:10:54 AM4/13/12
to mongod...@googlegroups.com
Not really I suppose you could use the distinct() command or pre-aggregate (which might work here) but really distinct would do the same as you do there so meh to that command.

Sam Millman

unread,
Apr 13, 2012, 10:13:08 AM4/13/12
to mongod...@googlegroups.com
Wait:


"but list all valies in client ( for example 200 000 rows ) for one
result value"

What do you mean? If you explain how amny documents go in and out I can answer that better.

If your iterating over 200k rows in your client side (not sure if the English means that) then it could be time consuming.
Reply all
Reply to author
Forward
0 new messages