How can I return an array of mongodb objects in pymongo (without a cursor)? Can MapReduce do this?

后端 未结 3 1597
情话喂你
情话喂你 2021-01-11 12:05

I have a db set up in mongo that I\'m accessing with pymongo.

I\'d like to be able to pull a small set of fields into a list of dictionaries. So, something like wha

3条回答
  •  广开言路
    2021-01-11 12:24

    What you can do is to call mapReduce in pymongo and pass it the find query as an argument, it could be like this:

    db.yourcollection.Map_reduce(map_function, reduce_function,query='{}')
    

    About the projections I think that you would need to do them in the reduce function since query only specify the selection criteria as it says in the mongo documentation

提交回复
热议问题