I am porting a program written in server side javascript to python using pymongo. The javscript program uses this syntax:
db.dbname.find(pattern1,pattern2).map( function(i){functionname(i) })
Pattern1 and pattern2 are valid mongodb query patterns. Functionname is a valid javascript function. All are defined in the javascript source file. I have searched the documentation but can't seem to find a pymongo find().map function (as opposed to map_reduce.)
How would this be re written in python?
1 Answer 1
You can just see what is map function in javascript doing. Map is a part of functional programming, but what it is doing can be simply described as follows: it is taking an array and modify every element in an array based on the function provided. You can think about it as a loop.
So you need to do the same loop in python. With comprehensions it will be something like this:
[functionname(i) for i in resultFromMongo]
Checkout this for a reference.