Although for most of developers, deploying database On Windows is not advised. For beginners like me, always need do some practise on Windows.
Currently I am studying replica sets, which asks me to run multiple servers at the same time with following commands.
I am studying mongoDB with python, I met this problem.
When I tried to open a url by python, I copied some code from internet like following:
# connect to mongo
connection = pymongo.MongoClient("mongodb://localhost")
# get a handle to the reddit database
db = connection.reddit
stories = db.stories
# drop existing collection
# get the reddit home page
reddit_page = urllib2.urlopen("https://www.reddit.com/r/technology/.json")
# parse the json into python objects
parsed = json.loads(reddit_page.read())
# iterate through every news item on the page
for item in parsed['data']['children']:
# put it in mongo
and met this error:
NameError: name urllib2 is not defined
Then I found that ‘urllib2’ is a lib for python2 while I use python3
Solution is easy by changing import lib
reddit_page = urllib.request.urlopen("https://www.reddit.com/r/technology/.json")