0

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?

3
  • this is vague - It's not possible to convert a document contains an objectId to json Commented Nov 21, 2017 at 7:32
  • @VanPeer So how ORMs handle this? Commented Nov 21, 2017 at 7:34
  • I meant what you said is not clear. Commented Nov 21, 2017 at 8:38

1 Answer 1

1

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/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.