我有2个课程(我使用的是Flask-mongoengine):
class ArticleCategory(db.Document):
name = db.StringField(verbose_name='Title', required=True, unique=True)
desc = db.StringField(verbose_name='Slug', required=True)
class Article(CreateUpdateMixin, DeletedMixin, db.Document):
title = db.StringField(verbose_name='Title', required=True)
slug = db.StringField(verbose_name='Slug', required=True, unique=True)
content = db.StringField(verbose_name='Content', required=True)
#Many-to-many relation
categories = db.ListField(db.ReferenceField(ArticleCategory),
verbose_name='Category', required=True)
def __unicode__(self):
return self.title
现在我想按特定类别(或类别名称)获取所有文章。我在mongoengine查询帮助中找不到像__eq
这样的运算符。
Article.objects(categories__in('some_category'))
等运算符失败。
答案 0 :(得分:1)
您的查询错误,请参阅文档http://mongoengine.readthedocs.io/en/latest/guide/querying.html#query-operators。
Article.objects(categories__in=['ARTICLE_CATEGORY_ID'])