我在mongo中设置了一个数据库,我正在使用pymongo进行访问.
我希望能够将一小组字段拖入字典列表中.所以,就像我输入mongo shell时的内容...
db.find({},{"variable1_of_interest":1, "variable2_of_interest":1}).limit(2).pretty()
Run Code Online (Sandbox Code Playgroud)
我想要一个python语句,如:
x = db.find({},{"variable1_of_interest":1, "variable2_of_interest":1})
Run Code Online (Sandbox Code Playgroud)
其中x是某种类型的数组结构而不是游标---也就是说,而不是迭代,如:
data = []
x = db.find({},{"variable1_of_interest":1, "variable2_of_interest":1})
for i in x:
data.append(x)
Run Code Online (Sandbox Code Playgroud)
我是否有可能使用MapReduce将其转化为单行?就像是
db.find({},{"variable1_of_interest":1, "variable2_of_interest":1}).map_reduce(mapper, reducer, "data")
Run Code Online (Sandbox Code Playgroud)
我打算将此数据集输出到R进行某些分析,但我想将IO集中在Python中.
Asy*_*sky 24
您不需要调用mapReduce,只需将光标转换为如下所示的列表:
>>> data = list(col.find({},{"a":1,"b":1,"_id":0}).limit(2))
>>> data
[{u'a': 1.0, u'b': 2.0}, {u'a': 2.0, u'b': 3.0}]
Run Code Online (Sandbox Code Playgroud)
其中col是你的db.collection对象.
但是对于大/大结果的警告导致每件事都被加载到内存中.
| 归档时间: |
|
| 查看次数: |
14443 次 |
| 最近记录: |