Query mongdb using hash or Json
We just released mongoid_hash_query which is the little brother of ActiveHashRelation gem.
It allows you to query mongodb (uses mongoid below) using hash or json! We use it build robust APIs in combination with Emberjs!
Comments
Why would someone want to use this gem? What problem does it solve? It is not clear to me from reading the README in the project home page.
Hi BPARANJ. The problem it solves is that it brings your mongoid dsl to the front-end developer. When you build an API, usually you have fixed API endpoints. For instance if you have a mongo collection, you will add fixed param checking in the controller.
For instance let’s say that you have the following collection:
class Person include Mongoid::Document field :first_name, type: String field :middle_name, type: String field :last_name, type: String field :age, type: Integer endThen in your controller you need to check if user has sent the params[:first_name]. If it has, you query your mongodb using resource = resource.where(first_name: params[:first_name]). Same goes for the rest of the params.
However that can be such a waste of time. These gems, allow you to skip these checks and essentially brings the mongodb api to the front-end. A front-end developer (using a modern framework like emberjs) can query ANYTHING using this api in a GET request. The params are converted in a hash in ruby and you just send them in mongoid_hash_query which does all the magic :)
I hope it helped!
Post a comment