Reputation: 1
I am having JSON collection fetched from MongoDB & I want to convert it into Hash.
How can I do so..?
Thanks in advance..
Upvotes: 0
Views: 653
Reputation: 42218
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.
Upvotes: 2