Join us Sept 17 at .local NYC! Use code WEB50 to save 50% on tickets. Learn more >
MongoDB Event
Docs 菜单
Docs 主页
/ / /
Django MongoDB后端

Django 和MongoDB功能兼容性

在此页面上,您可以找到有关 Django MongoDB后端支持和不支持的功能的信息。您还可以找到当前计划在未来版本中提供的功能。我们将根据用户需求对这些即将推出的功能进行优先级排序,您可以通过 创建 JIRA 问题 请求对某项功能的支持。

Django MongoDB后端支持以下操作,但性能可能较低:

操作
性能说明

$expr 操作

Queries that use the $expr operator might run slowly, since this operator often cannot predict which index to use and performs a collection scan. Some QuerySet operations, such as queries that specify an in lookup, use $expr to evaluate the query results and experience degraded performance.
We plan to address this performance issue in a post-GA release.

$lookup 操作

Queries that use the $lookup operator might run slowly. To improve performance, we recommend that you use embedded models instead of the $lookup operator when possible. To learn more about how to reduce $lookup operations, see the Reduce $lookup Operations guide in the MongoDB Atlas documentation.

本部分指示 Django MongoDB后端是否支持各种MongoDB功能。

MongoDB功能
当前支持

Atlas Search 索引

部分支持。您可以使用 Django MongoDB后端创建基本的Atlas Search索引,并指定索引名称和要索引的字段。不支持所有其他索引定义字段。

MongoDB不支持某些数据类型的Atlas Search索引。要查看不支持的类型列表,请参阅MongoDB Atlas文档中的数据类型限制

Atlas Vector Search 索引

部分支持。您可以使用 Django MongoDB后端创建基本的Atlas Vector Search索引,这些索引指定索引名称、要索引的字段以及相似度函数。不支持所有其他索引定义字段。

复合索引

嵌入式文档索引

地理空间索引

多键索引

部分索引

单字段索引

Unique indexes

创建模型后更新嵌入式模型索引

不支持

EmbeddedModelArrayField 索引

PolymorphicEmbeddedModelFieldPolymorphicEmbeddedModelArrayField 索引

不支持

Django MongoDB后端当前支持下表中未包含的所有MongoDB数据类型。要查看支持类型的完整列表,请参阅创建模型指南的MongoDB BSON字段部分。

BSON 数据类型
当前支持

Object

You can use embedded models and polymorphic embedded models to represent objects. If you are using the EmbeddedModelField field, the following limitations apply: - Foreign key fields are not supported. - Arbitrary or untyped embedded model fields are not supported. You must derive all fields from an EmbeddedModel class.

Regular Expression

支持。不过,我们计划在正式发布后的版本中支持这种类型。

MongoDB功能
当前支持

聚合操作

部分支持。Django MongoDB后端不包括MongoDB聚合框架的自定义 Django字段查找,但您可以使用 raw_aggregate() 方法。

Atlas Search 查询

删除操作

地理空间查询

Use the raw_aggregate() method to run geospatial queries instead of the GIS QuerySet API.

插入操作

读取操作

更新操作

向量搜索查询

MongoDB功能
当前支持

异步支持

身份验证

缓存数据存储

支持。不过,我们计划在正式发布后的版本中添加对此功能的支持。

Change Streams

支持。不过,我们计划在正式发布后的版本中添加对此功能的支持。

客户端字段级加密和Queryable Encryption

支持。不过,我们计划在正式发布后的版本中添加对此功能的支持。

集合交互

数据库交互

GridFS

支持。不过,我们计划在正式发布后的版本中添加对此功能的支持。

一个集合有多个模型

不支持

表示文档

Use models to represent MongoDB documents.

模式验证

支持。不过,我们计划在正式发布后的版本中添加对此功能的支持。

时间序列数据

事务

You can use Django MongoDB Backend's custom transactions API with the following limitations: - QuerySet.union() is not supported within a transaction. - Savepoints, or nested atomic blocks, are not supported. The outermost atomic block starts a transaction, and any subsequent atomic blocks have no effect. - Your MongoDB deployment must be a replica set or sharded cluster.

本部分指示 Django MongoDB后端是否支持各种 Django 功能。

Django MongoDB后端目前支持下表中未包含的所有 Django 字段。要查看支持字段的完整列表,请参阅“创建模型”指南的 Django 字段 部分。

Django 字段类型
当前支持

AutoField

支持。也不支持 BigAutoFieldSmallAutoField 类型。请改用 ObjectIdField

CompositePrimaryKey

不支持

DateTimeField

Microsecond granularity for DateTimeField values is not supported.

DurationField

DurationField stores milliseconds rather than microseconds.

ForeignKey

部分支持。您可以使用此字段类型,但有以下限制:

  • 如果可能,应使用 EmbeddedModelField 而不是 ForeignKey字段,以避免使用 $lookup 操作。 EmbeddedModelField 模拟MongoDB嵌入式文档,其性能优于 ForeignKey字段。 要学习;了解有关如何减少$lookup 操作的更多信息,请参阅Atlas文档中的减少 $lookup 操作指南。

  • 在 字段上 CASCADE 删除的性能不如使用ForeignKey EmbeddedModelField时的性能。

GeneratedField

不支持

JSONField

部分支持。您可以使用此字段类型,但有以下限制:

  • Django MongoDB后端无法区分JSON和SQL null 值。 使用 Value(None, JSONField())isnull 查找的查询会同时返回JSON和SQL null 值。

  • 某些使用 Q 对象的查询(例如 Q(value__foo="bar"))可能无法按预期运行。

  • 筛选 None 值会错误地返回其中不存在字段的对象。

Django MongoDB后端目前支持下表中未包含的所有 Django QuerySet 方法。要查看支持的方法,请参阅 Django 文档中的QuerySet API

Django QuerySet 功能
当前支持

delete()

You cannot use this method to perform queries that span multiple collections.

extra()

不支持

模式匹配查找

You can only use these lookups to query string fields.
The pattern-matching lookups are iexact, startswith, istartswith, endswith, iendswith, contains, icontains, regex, and iregex

prefetch_related()

不支持

raw()

支持。但是,您可以使用 raw_aggregate() 方法来运行使用 MongoDB聚合管道语法的查询。

update()

You cannot use this method to perform queries that span multiple collections.

Django MongoDB后端当前支持下表中未包含的所有数据库函数。要查看函数的完整列表,请参阅 Django 文档中的数据库函数。

Django 函数
当前支持

Chr

不支持

ExtractQuarter

不支持

MD5

不支持

Now

不支持

Ord

不支持

Pad

不支持

Repeat

不支持

Reverse

不支持

Right

不支持

SHA1, SHA224 , SHA256 , SHA384 , SHA512

不支持

Sign

不支持

Trunc

部分支持。不支持TruncDateTruncTime数据库函数的tzinfo参数。

Django 功能
当前支持

Django Admin

Django 身份验证

GeoDjango

部分支持。此 Web框架受支持但有以下限制:

Django MongoDB后端支持 Django 表单,但 PolymorphicEmbeddedModelFieldPolymorphicEmbeddedModelArrayField 不会出现在表单中。

Django MongoDB后端当前支持下表中未包含的所有管理命令。要查看命令的完整列表,请参阅 Django 文档中的可用命令。

Django 命令
当前支持

createcachetable

不支持

dumpdata

支持。不过,我们计划在正式发布后的版本中添加对此功能的支持。

inspectdb

支持。不过,我们计划在正式发布后的版本中添加对此功能的支持。

loaddata

支持。不过,我们计划在正式发布后的版本中添加对此功能的支持。

Django 功能
当前支持

通过迁移命令创建、删除和更新索引

部分支持。您无法更新嵌入式模型或大量字段上的索引。

不支持

migrate --fake-initial 选项

不支持

嵌入式模型的迁移

部分支持。迁移命令不会检测对 PolymorphicEmbeddedModelFieldPolymorphicEmbeddedModelArrayField 引用的嵌入式模型字段或嵌入式模型的更改。

当前支持

部分支持。要学习;了解有关此库的使用案例和限制的更多信息,请参阅 Django MongoDB CLI文档中的 Django过滤。

部分支持。要学习;了解有关此库的使用案例和限制的更多信息,请参阅 Django MongoDB CLI文档中的 Django Rest框架。

部分支持。要学习;了解有关此库的使用案例和限制的更多信息,请参阅 Django MongoDB CLI文档中的 Django allauth。

部分支持。要学习;了解有关此库的使用案例和限制的更多信息,请参阅 Django MongoDB CLI文档中的 Django 调试工具栏。

后退

事务

在此页面上