如何使用MongoEngine制作ArrayField?

时间:2019-04-16 02:14:36

标签: python django mongodb mongoengine

mongoengine的文档中没有ArrayField选项。这里是:http://docs.mongoengine.org/guide/defining-documents.html 我为诸如此类的未命名为ArrayField的东西而疯狂。甚至可以使用mongoengine做一个ArrayField吗?

1 个答案:

答案 0 :(得分:1)

我认为您正在寻找的是mongoengine中的ListField

更多详细信息在这里: http://docs.mongoengine.org/apireference.html#mongoengine.fields.ListField

例如

from mongoengine import Document

from mongoengine.fields import ListField
from mongoengine.fields import StringField

class User(Document):
    name = StringField()
    roles = ListField(StringField()) # something like ["ro", "rw"]