使用python 2.7,pymongo,mongoDB 2.6.1:从mongoDB文档中获取JSON
我有一个mongoDB集合。
现在我试图从它的几个字段,并将它的JSON列表到一个文件(这是另一方期望的输入)。
我尝试下面的代码:
my_file = open("test.csv", "w")
for doc in collection.find():
json.dumps({"command": doc["command"], "data": doc["data"]}, my_file)
,并得到了错误: KeyError异常: '命令'
缺少什么我在这里?
并集合中的所有文档都'command'?尝试使用'doc.get('command')' – 2014-09-21 11:18:54