From 591f57547b4dc876d8be6e31c944f8141f5e7a09 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 4 Jul 2023 13:07:45 +0500 Subject: [PATCH] Fixed TypeError: 'Collection' object is not callable. If you meant to call the 'insert' method on a 'Collection' object it is failing because no such method exists. * https://pymongo.readthedocs.io/en/stable/migrate-to-pymongo4.html#collection-insert-is-removed * https://pymongo.readthedocs.io/en/stable/migrate-to-pymongo4.html#collection-save-is-removed --- gerapy_item_pipeline/mongodb.py | 6 +++--- requirements.txt | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/gerapy_item_pipeline/mongodb.py b/gerapy_item_pipeline/mongodb.py index 973d957..fcef954 100644 --- a/gerapy_item_pipeline/mongodb.py +++ b/gerapy_item_pipeline/mongodb.py @@ -1,5 +1,5 @@ import pymongo -from gerapy_item_pipeline.settings import * +from .settings import * class MongoDBPipeline(object): @@ -62,13 +62,13 @@ def process_item(self, item, spider): item.get(self.item_primary_key_field, self.item_primary_key_default) if self.upsert: - self.db[collection_name].update({ + self.db[collection_name].update_one({ primary_key_field: item.get(primary_key_field) }, { '$set': item }, upsert=True) else: - self.db[collection_name].insert(item) + self.db[collection_name].insert_one(item) return item def close_spider(self, spider): diff --git a/requirements.txt b/requirements.txt index 0e801fc..2cfc44d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ scrapy>=2.0.0 -pymongo \ No newline at end of file +pymongo>=4,<5.0