I have a collection which contains both _id and id field. When I search by id field in mongo client everything is fine. When I search through mongomapper model like: Product.find_by_id(6) or Product.where(:id => 6) it return empty Plucky object and I can see that it looks for an _id field instead of id.
As I understand mongomapper just always using _id, no matter if you specifically want to find something by id.
Is there any work around for it or I'm doing it wrong?
I believe MongoMapper treats
idand_idboth equally.idis just a friendlier representation of_id.In your particular case, is there any reason that you need to have the
idfield as well? I'd recommend changing that, particularly if there is another more descriptive name which would fit. If you are actually using theidfield as a unique identifier (which it sounds like you might be), the best approach would probably be to store it in the_idfield instead. As you will already be aware, this is required on all MongoDB documents and can either be specified by you (your application), or added on later by your driver outside of the scope of your application code.Hope that helps.