From a14c22f37435104e4ff7c558b733c3f05a7710f5 Mon Sep 17 00:00:00 2001 From: kondaiahv Date: Thu, 9 May 2024 13:36:38 -0500 Subject: [PATCH] CASB-178258: Changes for pymongo-4.7+ --- django_mongodb_engine/compiler.py | 13 ++++++++----- django_mongodb_engine/south_adapter.py | 6 +++--- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/django_mongodb_engine/compiler.py b/django_mongodb_engine/compiler.py index a26c0af1..88d83fcc 100644 --- a/django_mongodb_engine/compiler.py +++ b/django_mongodb_engine/compiler.py @@ -109,10 +109,13 @@ def fetch(self, low_mark, high_mark): @safe_call def count(self, limit=None): - results = self.get_cursor() - if limit is not None: - results.limit(limit) - return results.count() + if(self.mongo_query): + return self.collection.count_documents(self.mongo_query) + return self.collection.estimated_document_count() + #results = self.get_cursor() + #if limit is not None: + # results.limit(limit) + #return results.count() @safe_call def order_by(self, ordering): @@ -129,7 +132,7 @@ def order_by(self, ordering): @safe_call def delete(self): options = self.connection.operation_flags.get('delete', {}) - self.collection.remove(self.mongo_query, **options) + self.collection.delete_many(self.mongo_query, **options) def get_cursor(self): if self.query.low_mark == self.query.high_mark: diff --git a/django_mongodb_engine/south_adapter.py b/django_mongodb_engine/south_adapter.py index 5d1138c4..3fa5619d 100644 --- a/django_mongodb_engine/south_adapter.py +++ b/django_mongodb_engine/south_adapter.py @@ -42,7 +42,7 @@ def add_column(self, table_name, field_name, field, keep_default=True): db_prep_save = field.get_db_prep_save(default, connection=connection) default = connection.ops.value_for_db(db_prep_save, field) # Update all the documents that haven't got this field yet - collection.update({name: {'$exists': False}}, + collection.update_many({name: {'$exists': False}}, {'$set': {name: default}}) if not keep_default: field.default = NOT_PROVIDED @@ -53,11 +53,11 @@ def alter_column(self, table_name, column_name, field, explicit_name=True): def delete_column(self, table_name, name): collection = self._get_collection(table_name) - collection.update({}, {'$unset': {name: 1}}) + collection.update_many({}, {'$unset': {name: 1}}) def rename_column(self, table_name, old, new): collection = self._get_collection(table_name) - collection.update({}, {'$rename': {old: new}}) + collection.update_many({}, {'$rename': {old: new}}) def create_unique(self, table_name, columns, drop_dups=False): collection = self._get_collection(table_name)