@@ -40,14 +40,28 @@ def process_item(self, item, spider):
40
40
:param spider: spider object
41
41
:return:
42
42
"""
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 ,
50
56
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 :
51
65
self .db [collection_name ].update ({
52
66
primary_key_field : item .get (primary_key_field )
53
67
}, {
0 commit comments