How to conver JSON collection into Hash using Rails 3
I am having JSON collection fetched from MongoDB & 开发者_运维知识库I want to convert it into Hash.
How can I do so..?
Thanks in advance..
How did you fetch it from mongo? the ruby mongo driver automatically gives you ruby hashes.
EDIT: To take the second question into account
In mongo, queries don't actually execute until you call something that requires them to execute. Before you call to_json, you actually are still playing with a query object.
Instead of to_json, try just using to_a to get an array of hashes back.
精彩评论