简体   繁体   中英

JSON issue with MongoDB ObjectId

As you know MongoDB documents has at least one ObjectId named _id . It's not possible to convert a document contains an ObjectId to JSON . currently I have two solutions to convert this document to JSON :

del doc['_id']

or create a new document with a string instance of that field.

What it just works when I know which field contains ObjectId . What to do if I have multiple ObjectId and I don't know what are they?

MongoDB returns a BSON (not a JSON ) document, so actually you want to convert a BSON document into JSON document.

Try to take a look into this artickle: https://technobeans.com/2012/09/10/mongodb-convert-bson-to-json/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM