Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ MONGODB_SEPARATE_COLLECTIONS = True
| `MONGODB_REPLICA_SET` | None | Yes, for replica sets | Set this if you want to enable replica set support. The option should be given the name of the replica sets you want to connect to. `MONGODB_URI` should point at your config servers. |
| `MONGODB_REPLICA_SET_W` | 0 | No | Best described in the [pymongo docs][2]. Write operations will block until they have been replicated to the specified number or tagged set of servers. `w=<int>` always includes the replica set primary (e.g. `w=3` means write to the primary and wait until replicated to two secondaries). Passing `w=0` disables write acknowledgement and all other write concern options.
| `MONGODB_STOP_ON_DUPLICATE` | 0 | No | Set this to a value greater than 0 to close the spider when that number of duplicated insertions in MongoDB are detected. If set to 0, this option has no effect. |
| `MONGODB_VERIFY_SSL` | None | No | Specifies whether to validate certificate for connection. None, ssl.CERT_NONE, ssl.CERT_REQUIRED, or ssl.CERT_OPTIONAL |



[1]: http://docs.mongodb.org/manual/reference/connection-string
[2]: http://api.mongodb.org/python/current/api/pymongo/mongo_replica_set_client.html#pymongo.mongo_replica_set_client.MongoReplicaSetClient
Expand Down
9 changes: 6 additions & 3 deletions scrapy_mongodb.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import datetime
import logging

import ssl
import six
from pymongo import errors
from pymongo.mongo_client import MongoClient
Expand Down Expand Up @@ -38,6 +38,7 @@ class MongoDBPipeline(BaseItemExporter):
'buffer': None,
'append_timestamp': False,
'stop_on_duplicate': 0,
'verify_ssl': None
}

# Item buffer
Expand Down Expand Up @@ -78,7 +79,8 @@ def open_spider(self, spider):
connection = MongoClient(
self.config['uri'],
fsync=self.config['fsync'],
read_preference=ReadPreference.PRIMARY)
read_preference=ReadPreference.PRIMARY,
ssl_cert_reqs=self.config['verify_ssl'])

# Set up the database
self.database = connection[self.config['database']]
Expand Down Expand Up @@ -145,7 +147,8 @@ def configure(self):
('unique_key', 'MONGODB_UNIQUE_KEY'),
('buffer', 'MONGODB_BUFFER_DATA'),
('append_timestamp', 'MONGODB_ADD_TIMESTAMP'),
('stop_on_duplicate', 'MONGODB_STOP_ON_DUPLICATE')
('stop_on_duplicate', 'MONGODB_STOP_ON_DUPLICATE'),
('verify_ssl', 'MONGODB_VERIFY_SSL')
]

for key, setting in options:
Expand Down