Ruby: Rename keys in array of hashes? -


how rename _id keys id in array of mongodb documents?

so, want make this:

[{"_id"=>"1", "name"=>"matt"}, {"_id"=>"2", "name"=>"john"}, ...] 

into this:

[{"id"=>"1", "name"=>"matt"}, {"id"=>"2", "name"=>"john"}, ...] 

i found complete solution.

mongo_db['users'].find().to_a.each |u|   u['id'] = u.delete '_id' end.to_json 

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -