例如..在 Mongodb 中..
> db.test.findOne({}, {'mapField.FREE':1})
{
"_id" : ObjectId("4fb7b248c450190a2000006a"),
"mapField" : {
"BOXFLUX" : {
"a" : "f",
}
}
}
'mapField' 字段由 Mongoengine 的 MapField 组成。
和“mapField”字段有密钥和数据的日志..但我只检索了“BOXFLUX”..
该查询在 MongoEngine 中不起作用......
例如..
BoxfluxDocument.objects( ~~ querying ~~ ).only('mapField.BOXFLUX')
如你看到的..仅('mapField.BOXFLUX')或仅仅('mapField__BOXFLUX')不起作用。
它检索所有“mapField”数据,包括“BOXFLUX”数据。
我怎样才能只检索MapField的一个字段???
我看到有一张票:https://github.com/hmarr/mongoengine/issues/508 https://github.com/hmarr/mongoengine/issues/508
对我有用这里是一个示例测试用例:
def test_only_with_mapfields(self):
class BlogPost(Document):
content = StringField()
author = MapField(field=StringField())
BlogPost.drop_collection()
post = BlogPost(content='Had a good coffee today...',
author={'name': "Ross", "age": "20"}).save()
obj = BlogPost.objects.only('author__name',).get()
self.assertEquals(obj.author['name'], "Ross")
self.assertEquals(obj.author.get("age", None), None)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)