Skip to content

Commit 55c2379

Browse files
committed
to 002
1 parent efe9a3a commit 55c2379

File tree

3 files changed

+28
-8
lines changed

3 files changed

+28
-8
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Gerapy Item Pipeline Changelog
22

3+
## 0.0.1 (2021-01-17)
4+
5+
### Features
6+
7+
* Fix bug of MongoDB
8+
39
## 0.0.1 (2020-07-27)
410

511
### Features

gerapy_item_pipeline/__version__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
VERSION = (0, 0, '1')
1+
VERSION = (0, 0, '2')
22

33
version = __version__ = '.'.join(map(str, VERSION))

gerapy_item_pipeline/mongodb.py

+21-7
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,28 @@ def process_item(self, item, spider):
4040
:param spider: spider object
4141
:return:
4242
"""
43-
collection_name = getattr(item, self.collection_name_field) or \
44-
item.get(self.collection_name_field,
45-
self.collection_name_default)
46-
if self.upsert:
47-
# get primary key field or use primary key default
48-
primary_key_field = getattr(item, self.item_primary_key_field) or \
49-
item.get(self.item_primary_key_field,
43+
# update collection_name
44+
if isinstance(item, dict):
45+
collection_name = item.get(self.collection_name_field,
46+
self.collection_name_default)
47+
else:
48+
if hasattr(item, self.collection_name_field):
49+
collection_name = getattr(item, self.collection_name_field) or self.collection_name_default
50+
else:
51+
collection_name = item.get(self.collection_name_field,
52+
self.collection_name_default)
53+
# update primary_key_field
54+
if isinstance(item, dict):
55+
primary_key_field = item.get(self.item_primary_key_field,
5056
self.item_primary_key_default)
57+
else:
58+
if hasattr(item, self.item_primary_key_field):
59+
primary_key_field = getattr(item, self.item_primary_key_field) or self.item_primary_key_default
60+
else:
61+
primary_key_field = getattr(item, self.item_primary_key_field) or \
62+
item.get(self.item_primary_key_field,
63+
self.item_primary_key_default)
64+
if self.upsert:
5165
self.db[collection_name].update({
5266
primary_key_field: item.get(primary_key_field)
5367
}, {

0 commit comments

Comments
 (0)