我刚刚第一次安装和pymongo并立即遇到麻烦。从MongoDB网站上的基本python tutorial运行示例时,我立即收到此响应:
Traceback (most recent call last):
File "pymongo.py", line 1, in <module>
from pymongo import MongoClient
File "/Users/user/Documents/Tweepy scrapers/pymongo.py", line 1, in <module>
from pymongo import MongoClient
ImportError: cannot import name MongoClient
代码如下所示:
from pymongo import MongoClient
from datetime import datetime
client = MongoClient()
db = client.test
result = db.restaurants.insert_one(
{
"address": {
"street": "2 Avenue",
"zipcode": "10075",
"building": "1480",
"coord": [-73.9557413, 40.7720266]
},
"borough": "Manhattan",
"cuisine": "Italian",
"grades": [
{
"date": datetime.strptime("2014-10-01", "%Y-%m-%d"),
"grade": "A",
"score": 11
},
{
"date": datetime.strptime("2014-01-16", "%Y-%m-%d"),
"grade": "B",
"score": 17
}
],
"name": "Vella",
"restaurant_id": "41704620"
}
)
print result.inserted_id
我正在运行python 2.7和pymongo 3.0.3