Hey,
I am having JSON collection fetched from MongoDB & I want to convert it into Hash.
How can I do so..?
Thanks in advance..
Hey,
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.
@Matt Briggs : yes, you are right.
but here I want to apply will_paginate on result.
Have look -- @result = search_from_mongo(search, tab)
While I inspect @result.class, it gives MongoID:criteria... on which I can't apply will_paginate's method. Than I tried this --- @result_j = @result.to_json() @result_a = ActiveSupport::JSON.decode(@result_j)
and inspect @result_a.class which gives me Array as output