I am using Rails 4.1.5 & Mongoid 4.0. My apis are returning mongo id's as hash
{
_id: {
$oid: "541e79bc616b684e75000000"
}
created_at: "2014-09-21T07:09:48.599Z"
}
I want something like this
{
id: "541e79bc616b684e75000000"
created_at: "2014-09-21T07:09:48.599Z"
}
I have checked this question already, but i am not sure in which file i need to put changes mentioned in this answer
You need to create a file in config/initializers and put the code there.
UPDATE:
Use the following code:
module BSON
class ObjectId
def to_json(*args)
to_s.to_json
end
def as_json(*args)
to_s.as_json
end
end
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With