在Mongoengine中Document如下
[code=python]
class Bar(Document):
name = StringField()
class Foo(Document):
bar = ReferenceField(Bar)
[/code]
若直接查询ReferenceField中的value就会报错"InvalidQueryError :Cannot perform join in mongoDB"
[code=python]
foos = Foo.objects(bar__name="test")
[/code]
此时就需要进行两次查询:
[code=python]
bars = Bar.objects(name='test')
foos = Foo.objects(bar__in=bars)
[code=python]
class Bar(Document):
name = StringField()
class Foo(Document):
bar = ReferenceField(Bar)
[/code]
若直接查询ReferenceField中的value就会报错"InvalidQueryError :Cannot perform join in mongoDB"
[code=python]
foos = Foo.objects(bar__name="test")
[/code]
此时就需要进行两次查询:
[code=python]
bars = Bar.objects(name='test')
foos = Foo.objects(bar__in=bars)
[/code]
此解决方案来自http://stackoverflow.com/questions/6570432/querying-referencefields-with-mongoengine