简体   繁体   中英

How do I make an ArrayField using MongoEngine?

There isn't an ArrayField option in mongoengine's documentation. Here it is: http://docs.mongoengine.org/guide/defining-documents.html I'm going crazy over how something like that isn't named ArrayField. Is it even possible to do an ArrayField using mongoengine?

I think what you are looking for is ListField in mongoengine.

More details here: http://docs.mongoengine.org/apireference.html#mongoengine.fields.ListField

eg

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"]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM