Sameer Shaikh
Sameer Shaikh

Reputation: 265

Scrapy Mongodb Connection

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??

Upvotes: 1

Views: 1064

Answers (1)

nickmilon
nickmilon

Reputation: 1372

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()

Upvotes: 2

Related Questions