L3K0V
L3K0V

Reputation: 1134

Mongoengine - JSONify EmbeddedDocumentListField

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

Answers (1)

L3K0V
L3K0V

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

Related Questions