Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

Can't convert to JSON #13

Closed
aigarsdz opened this issue Nov 28, 2018 · 2 comments
Closed

Can't convert to JSON #13

aigarsdz opened this issue Nov 28, 2018 · 2 comments

Comments

@aigarsdz
Copy link

After calling #to_json on a query result, i get an error:

no overload matches 'BSON::ObjectId#to_json' with type JSON::Builder

Am I doing something wrong or is this functionality not supported?

Disclaimer: I'm new to Crystal and Amber.

@sam0x17
Copy link
Owner

sam0x17 commented Nov 30, 2018

Thanks for catching this. That part of the code was untested and carried over from a very old version of granite orm. Now you should be able to call .to_json on any mongo_orm object. That said, do know that Mongo uses something called BSON, which is slightly different, and calling .to_bson will already give you a BSON object, and .to_bson.to_s is very similar to JSON. The .to_json method I wrote will give you crystal-formatted datetime values, while the .to_bson method will give you things in Mongo's internal formats.

@aigarsdz
Copy link
Author

That's good to know, thank you!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants