Field aliases with Mongoid and Rails

前端 未结 3 708
萌比男神i
萌比男神i 2021-01-02 13:56

It\'s common practice in MongoDB to use short key names to save space. For example, one might want to use \"fn\" instead of \"first_name\"

However in your app, you\

3条回答
  •  悲哀的现实
    2021-01-02 14:36

    I've never seen short key names in any MongoDB projects, so I wouldn't say it's common practice. I don't think you'd see a noticeable speed improvement and it would complicate your code unnecessarily. Descriptive names are good so long they aren't so descriptive that it takes you forever to type.

    There's lots of MongoDB open-source projects. Just do a search on github.

    -- edit below --

    This was a pretty opinionated answer. Overwriting the processing methods (https://github.com/mongoid/mongoid/blob/master/lib/mongoid/attributes/processing.rb) as described in other answers is more appropriate in the scenario where you MUST have small field names.

提交回复
热议问题