Rails Query MongoDB General Query

Source: Internet
Author: User
Tags ruby on rails

Ruby on Rails is well-integrated with MongoDB, the Gem pack:

Address:https://rubygems.org/gems/mongoid

Documentation: https://docs.mongodb.com/ecosystem/tutorial/ruby-mongoid-tutorial/#ruby-mongoid-tutorial

Latest queries that are also used

Model.where (name:/abc/)

This can look up all the contents of the Name field in the model table with ABC.

Pagination, can be combined with willpage

defSelf.paginate (options ={}) options[:p age]=options[:p age].to_i options[:p Age]= 1ifoptions[:p Age] = =0 Options=base_options Options:: Willpaginate::collection.create (options[:p age], options[:p er_page])|pager|Items_count= Options[:total_entries] | |self.count fill_pager_with Self.skip (Options[:offset]). Limit (options[:p er_page]), items_count, pager end end defself.base_options (options) options[:p Age]|| = 1options[:p Er_page]|| = 20Options[:offset]= (options[:p age].to_i-1) *options[:p er_page].to_i options EnddefSelf.fill_pager_with (medias, size, pager) pager.replace medias.to_a pager.total_entries=Size End

Rails Query MongoDB General Query

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.