1

I want to add index on ListField.Here is my code:

class Post(Document):

    meta = {"indexs":"testcomments.comment_id"}

    _id = StringField()
    txt = StringField()
    testcomments = EmbeddedDocumentField(Comment)
    comments = ListField(EmbeddedDocumentField(Comment))

class Comment(EmbeddedDocument):

    comment = StringField()
    comment_id = StringField()
    ...

...


I know how to add index on EmbeddedDocumentField (meta = {"indexs":"testcomments.comment_id"}),but how to add index on comments?

1 Answer 1

1

I believe it would work the same way for the list, thus

meta = {
"indexes": [
    "testcomments.comment_id",
    "comments.comment_id",    # or simply 'comments' if you want a multikey index
    ]
}

Note that you can check the indexes being created with

col = Page._get_collection()
c.index_information()

If you use the dict form to define indexes e.g: meta = {'indexes': [{'fields': ['comments.comment_id']}}, you can have more granularity on the index definition (and syntax closer to pymongo/mongodb)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.