DEV Community

Discussion on: Flask Rest API -Part:1- Using MongoDB with Flask

Collapse
 
ikhrome profile image
Ivan Khromov • Edited

Helpful note to everyone, who wants MongoEngine to serialize JSON like this:

{
    "id": "5f0b54728a42acf154e2082d",
    // the rest of document
}
Enter fullscreen mode Exit fullscreen mode

not this:

{
    "_id": {
        "$oid": "5f0b54728a42acf154e2082d"
    }
    // ... the rest of document
}
Enter fullscreen mode Exit fullscreen mode

Install MongoEngine GoodJSON library and extend Movie class like this:

from .db import db
import mongoengine_goodjson as gj

class Movie(gj.Document):
#the rest of code here ...
Enter fullscreen mode Exit fullscreen mode
Collapse
 
paurakhsharma profile image
Paurakh Sharma Humagain

Wow, that's cool. Thank you.
I was doing manual normalization, but this looks awesome.