0

I just installed and pymongo for the first time and immediately had trouble. When running the example from the basic python tutorial on the MongoDB website I immediately get this response:

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

The code looks like this:

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

I'm running python 2.7 and pymongo 3.0.3

hegemonni
  • 1
  • 1

0 Answers0