-
Notifications
You must be signed in to change notification settings - Fork 134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Serializing a BSON document to a simple JSON #354
Comments
Hi @erfanium, thanks for reaching out. There isn't a way to do this directly from a We recently discussed doing something that might help in this case: RUST-1178. See #191 for some related discussion. What that ticket proposes is adding a way to opt into having the driver produce "plain" JSON for types such as One workaround currently available would be to define a type modeling your data that implements |
Thank you @kmahar
I wanna add that it's not really my own logic, MongoDB Atlas Data Api uses this logic for response bodies, so I think it's necessary to have simple-json serialization in official bson libs. |
@erfanium Atlas Data API supports both plain and extended JSON, with the caveat that the plain format can lead to data loss because not all BSON types are representable in plain JSON (see docs). Due to these limitations, we've chosen not to support plain JSON in this library at this time. If you want to use this BSON library with Atlas Data API I would strongly recommend having your endpoints return and accept extended JSON, as it will ensure you do not lose any data or inadvertently change the data type of any fields in your documents. |
I would like to quickly bring this back and ask: since we cannot make both JSON and BSON with one struct, is there really a point of using bson features like uuids and dates instead of just strings? |
@gamertike databases can perform more optimizations when they know a field is a UUID, or Date |
I wonder is there any way to serialize a bson document to a simple json (not extjson)?
I know there's two similar methods
Bson::into_relaxed_extjson
andBson::into_canonical_extjson
but they convert them into extjson, not simple json, which i don't want.Here's is an example of my expected result.
This is exactly the same behavior of
JSON.stringify(bson_document)
in JavaScriptThe text was updated successfully, but these errors were encountered: