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
Post a Comment