diff --git a/apscheduler/jobstores/mongodb.py b/apscheduler/jobstores/mongodb.py index 7dbc3b127..ea3097ddc 100644 --- a/apscheduler/jobstores/mongodb.py +++ b/apscheduler/jobstores/mongodb.py @@ -54,7 +54,7 @@ def __init__(self, database='apscheduler', collection='jobs', client=None, def start(self, scheduler, alias): super(MongoDBJobStore, self).start(scheduler, alias) - self.collection.ensure_index('next_run_time', sparse=True) + self.collection.create_index('next_run_time', sparse=True) @property def connection(self): @@ -83,7 +83,7 @@ def get_all_jobs(self): def add_job(self, job): try: - self.collection.insert({ + self.collection.insert_one({ '_id': job.id, 'next_run_time': datetime_to_utc_timestamp(job.next_run_time), 'job_state': Binary(pickle.dumps(job.__getstate__(), self.pickle_protocol)) @@ -96,13 +96,13 @@ def update_job(self, job): 'next_run_time': datetime_to_utc_timestamp(job.next_run_time), 'job_state': Binary(pickle.dumps(job.__getstate__(), self.pickle_protocol)) } - result = self.collection.update({'_id': job.id}, {'$set': changes}) - if result and result['n'] == 0: + result = self.collection.update_one({'_id': job.id}, {'$set': changes}) + if result and result.matched_count == 0: raise JobLookupError(job.id) def remove_job(self, job_id): - result = self.collection.remove(job_id) - if result and result['n'] == 0: + result = self.collection.delete_one({'_id': job_id}) + if result and result.deleted_count == 0: raise JobLookupError(job_id) def remove_all_jobs(self): diff --git a/docs/versionhistory.rst b/docs/versionhistory.rst index 6476ef17b..623b3e273 100644 --- a/docs/versionhistory.rst +++ b/docs/versionhistory.rst @@ -10,6 +10,8 @@ APScheduler, see the :doc:`migration section `. * Fixed Zookeeper job store using backslashes instead of forward slashes for paths on Windows (PR by Laurel-rao) * Pinned ``tzlocal`` to a version compatible with pytz +* Fixed deprecation warnings on the MongoDB job store and increased the minimum PyMongo + version to 3.0 3.6.3 diff --git a/setup.py b/setup.py index 1531cb110..e4852a638 100644 --- a/setup.py +++ b/setup.py @@ -47,7 +47,7 @@ ':python_version == "2.7"': ['futures', 'funcsigs'], 'asyncio:python_version == "2.7"': ['trollius'], 'gevent': ['gevent'], - 'mongodb': ['pymongo >= 2.8'], + 'mongodb': ['pymongo >= 3.0'], 'redis': ['redis >= 3.0'], 'rethinkdb': ['rethinkdb >= 2.4.0'], 'sqlalchemy': ['sqlalchemy >= 0.8'],