I have a Rails/Mongoid app that displays data client-side using highcharts. Right now, to pass the data to Javascript, I use a Mongoid query and Rails' as_json/to_json in the template file. This seems very inefficient to me because the json data has to be parsed into ruby structures, and then re-converted to JSON. This is okay when there is a small amount of data, but in my case, there can be a lot.
So my question is, how can I do a raw mongodb query, and just write the output directly to the Rails response buffer without going through Ruby JSON serialization/deserialization?