加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

Django:长字段(BigIntegerField)用于MongoDB

发布时间:2020-12-20 13:29:50 所属栏目:Python 来源:网络整理
导读:我想指定一个模型字段来存储MongoDB中的Long整数类型.我已经尝试使用BigIntegerField,但它仍然作为MongoDB中的Integer字段保存.我尝试过使用: models.BigIntegerField() 我应该使用哪个模型字段? 注意:我已经将django-nonrel用于DJango-MongoDB关系. 解决
我想指定一个模型字段来存储MongoDB中的Long整数类型.我已经尝试使用BigIntegerField,但它仍然作为MongoDB中的Integer字段保存.我尝试过使用:

models.BigIntegerField()

我应该使用哪个模型字段?
注意:我已经将django-nonrel用于DJango-MongoDB关系.

解决方法

你节省了足够多的价值吗?你正在使用什么版本的python也可能很重要.来自API文档:

A Python int will be saved as a BSON int32 or BSON int64 depending on
its size. A BSON int32 will always decode to a Python int. In Python
2.x a BSON int64 will always decode to a Python long. In Python 3.x a BSON int64 will decode to a Python int since there is no longer a long type.

此外,python long应始终映射到BSON 64位整数:

http://api.mongodb.org/python/2.3rc1/api/bson/son.html

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读