Daniel W
unread,Oct 31, 2011, 12:15:39 PM10/31/11Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to mongodb-user
I have a collection with this index.
"key" : {
"g" : "2d",
"c" : 1,
"s.s" : 1
}
I'm trying to determine the bounding box for all docs with a certain
value of c, so that I can randomly sample from within that box.
I wrote a map/reduce in python, and when I run it, it just hangs for
hours, even on a query that returns only 2 documents. Is there a bug
in my map/reduce? Is there a better way to do this?
def boundingbox(campaign, collection):
map = Code("function () {"
" emit ('minlt', this.g[1]);"
" emit ('maxlt', this.g[1]);"
" emit ('minln', this.g[0]);"
" emit ('maxln', this.g[0]);"
"}")
reduce = Code("function (key, values) {"
" if (key=='maxlt' || key=='maxln') { "
" var thismax=-180;"
" for (var i = 0; i < values.length; i++) {"
" thismax = Math.max(thismax,values[i]);"
" }"
" return thismax;"
" }"
" else {"
" var thismin=180; "
" for (var i = 0; i < values.length; i++) {"
" thismin = Math.min(thismin,values[i]);"
" }"
" return thismin;"
" }"
"}"
)
resultcoll = collection.map_reduce(map, reduce, "myresults",
query={'c':campaign})
results=resultcoll.find()
results = [row for row in results]
return results