Python脚本在使用mongoDB时给出了属性错误

时间:2017-06-29 09:51:13

标签: python mongodb

这是我的Python脚本:

import pymongo

from bson.objectid import ObjectId

connection = pymongo.Connection();

db = connection["tutorial"];
employees = db["employees"];

employees.insert({"name": "Lucas Hightower", 'gender':'m', 'phone':'520-555-1212', 'age':8});

cursor = db.employees.find();
for employee in db.employees.find():
    print(employee);

print(employees.find({"name":"Rick Hightower"})[0]);


cursor = employees.find({"age": {"$lt": 35}});
for employee in cursor:
     print("under 35: %s" % employee);


diana = employees.find_one({"_id":ObjectId("4f984cce72320612f8f432bb")});
print("Diana %s" % diana);hon Script:

当我执行以下python时,我收到以下错误:

我在Windows机器上运行脚本

错误:connection = pymongo.Connection(); AttributeError:module' pymongo'没有属性'连接'

1 个答案:

答案 0 :(得分:0)

我不知道你正在使用哪种版本的pymongo。但基于latest document

./monitor_cpu.sh: line 6: [: 99.25: integer expression expected
Normal