2

I am scraping the data using scrapy.Now i want to store the data in mongo db for that i install pymongo but i am unable to connect to the databse Here is my code for settings.py

ITEM_PIPELINES = ['tutorial.pipelines.TutorialPipeline',]
MONGODB_SERVER = "localhost"
MONGODB_PORT = 27017
MONGODB_DB = "test"
MONGODB_COLLECTION = "raw_prod"

Here is the code for pipelines.py

import pymongo
from pymongo import Connection

class TutorialPipeline(object):

    def __init__(self):
        connection = pymongo.Connection(settings['MONGODB_SERVER'], settings['MONGODB_PORT'])
        db = connection[settings['MONGODB_DB']]
        self.collection = db[settings['MONGODB_COLLECTION']]

I am getting the following error

cannot import name Connection

Where am i going wrong??

Sameer Shaikh
  • 273
  • 1
  • 9
  • 21

1 Answers1

3

there is no such thing as 'Connection' in current pymongo (version 3) to connect you must use MongoClient
to connect to a db on local host and standard 27017 port

from pymongo import MongoClient; c = MongoClient()

nickmilon
  • 1,332
  • 1
  • 10
  • 9