@@ -80,7 +80,6 @@ def create_mongodb_index(
8080 model ,
8181 schema_editor ,
8282 * ,
83- connection = None , # noqa: ARG001
8483 field = None ,
8584 unique = False ,
8685 column_prefix = "" ,
@@ -126,17 +125,49 @@ def create_mongodb_index(
126125
127126class SearchIndex (Index ):
128127 suffix = "search"
128+ # Maps Django internal type to atlas search index type.
129+ mongo_data_types = {
130+ "AutoField" : "number" ,
131+ "BigAutoField" : "number" ,
132+ "BinaryField" : "string" ,
133+ "BooleanField" : "boolean" ,
134+ "CharField" : "string" ,
135+ "DateField" : "date" ,
136+ "DateTimeField" : "date" ,
137+ "DecimalField" : "number" ,
138+ "DurationField" : "number" ,
139+ "FileField" : "string" ,
140+ "FilePathField" : "string" ,
141+ "FloatField" : "double" ,
142+ "IntegerField" : "number" ,
143+ "BigIntegerField" : "number" ,
144+ "GenericIPAddressField" : "string" ,
145+ "JSONField" : "document" ,
146+ "OneToOneField" : "number" ,
147+ "PositiveBigIntegerField" : "number" ,
148+ "PositiveIntegerField" : "number" ,
149+ "PositiveSmallIntegerField" : "number" ,
150+ "SlugField" : "string" ,
151+ "SmallAutoField" : "number" ,
152+ "SmallIntegerField" : "number" ,
153+ "TextField" : "string" ,
154+ "TimeField" : "date" ,
155+ "UUIDField" : "uuid" ,
156+ "ObjectIdAutoField" : "objectId" ,
157+ "ObjectIdField" : "objectId" ,
158+ "EmbeddedModelField" : "embeddedDocuments" ,
159+ }
129160
130161 def __init__ (self , * expressions , ** kwargs ):
131162 super ().__init__ (* expressions , ** kwargs )
132163
133164 def create_mongodb_index (
134- self , model , schema_editor , connection = None , field = None , unique = False , column_prefix = ""
165+ self , model , schema_editor , field = None , unique = False , column_prefix = ""
135166 ):
136167 fields = {}
137168 for field_name , _ in self .fields_orders :
138169 field_ = model ._meta .get_field (field_name )
139- type_ = connection .mongo_data_types [field_ .get_internal_type ()]
170+ type_ = self .mongo_data_types [field_ .get_internal_type ()]
140171 field_path = column_prefix + model ._meta .get_field (field_name ).column
141172 fields [field_path ] = {"type" : type_ }
142173 return SearchIndexModel (
@@ -166,7 +197,7 @@ def _check_similarity_functions(self, similarities):
166197 )
167198
168199 def create_mongodb_index (
169- self , model , schema_editor , connection = None , field = None , unique = False , column_prefix = ""
200+ self , model , schema_editor , field = None , unique = False , column_prefix = ""
170201 ):
171202 similarities = (
172203 itertools .cycle ([self .similarities ])
0 commit comments