Projection or remove OID

9 views
Skip to first unread message

Paulo Cauca

unread,
May 23, 2020, 10:11:25 AM5/23/20
to MongoEngine Users

Hi Guys ,  I need some help to understand how I can remove OID from my return.

I'm doing a web service to return to my app mobile, 


When I call this url /service for exemple 

clinica = Clinica.objects()

return jsonify(clinica)



I receive this return 


[
{
"_id": {
"$oid": "5cf3234012c113eb42407c18"
},
"name": "Clinica Test"
},
    {
"_id": {
"$oid": "kjaklsdj81374lkjsdf"
},
"name": "Clinica Test2"
},
]


I'd like to receive 

[
{
"_id": 5cf3234012c113eb42407c18,
"name": "Clinica Test"
},
   {
"_id": kjaklsdj81374lkjsdf,
"name": "Clinica Test2"
},



class Clinica(db.Document):
name = db.StringField()


I do need to do somenthing in model ? or does have a project that I can use in the object ?

Thank you for help 


xiaojie luo

unread,
May 23, 2020, 11:49:48 AM5/23/20
to mongoeng...@googlegroups.com
I think you should do this.

clinica = Clinica.objects().first()
return jsonify(clinica.to_dict())




Paulo Cauca <paulo...@gmail.com> 于 2020年5月23日周六 下午10:11写道:
--
You received this message because you are subscribed to the Google Groups "MongoEngine Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongoengine-us...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongoengine-users/4da3da45-0436-4868-8820-1fb64edf3cc6%40googlegroups.com.

Paulo Cauca

unread,
May 23, 2020, 3:01:55 PM5/23/20
to mongoeng...@googlegroups.com
Hi, 
I tried but receive the error message :

TypeError: Object of type AttributeError is not JSON serializable



--
[Atte.]
{name: Paulo Cauca}

Reply all
Reply to author
Forward
0 new messages