Reputation: 1134
Is there an easy way to return EmbeddedDocumentListField
as JSON array in Mongoengine and Flask?
I've tried already to dump
with bson.json_util
, but only array of keys without values was returned. I have no aditional changes in model like to_json()
method etc.
Upvotes: 2
Views: 635
Reputation: 1134
Okay, I succeeded with:
from bson.json_util import loads, dumps
...
c = Course.objects.get_or_404(id=course_id)
json = loads(c.to_json())
return dumps(json['assignments'])
First query target Document, load it as JSON and dumps only assignments array of EmbeddedDocumentListField
Upvotes: 1