mongoid4

setting mongoid hash field values

限于喜欢 提交于 2020-01-02 00:50:19
问题 I'm using Mongoid in a Rails project (both 4.0.x), and I've got a document with a hash field that stores some schema-less data. class Thing field :name, type: String field :mass, type: Integer field :info, type: Hash end With this setup, I can query for things, say, that have a key :endDate like so: Thing.where("info.endDate"=>{'$exists'=>true}) And that's all nice and handy. Using a hash field for this :info field is nice because what I want to store doesn't have a fixed schema and varies

Rails 4: Use MySql and MongoDB together

家住魔仙堡 提交于 2019-12-21 03:19:27
问题 I'm trying to make an application in rails 4 using MongoDB(mongoid) and MySQL together. But I'm not able to set it up. I'm following the steps below: rails new myapp -d mysql Then added these lines to Gemfile: gem "mongoid" gem "bson_ext" bundle install rails g mongoid:config The step 4 fails. I'm not able to figure out the problem. It shows the following error. /home/devesh/.rvm/gems/ruby-2.2.2/gems/mongoid-1.0.6/lib/mongoid/associations.rb:5:in require': /home/devesh/.rvm/gems/ruby-2.2.2

mongoid combination of any_of and between

纵饮孤独 提交于 2019-12-13 18:00:27
问题 I need to achieve something like: queryable.any_of( between(:average_nightly_min_price, [10,100]), between(:average_nightly_max_price, [110,1100]) ) is it possible using the combination of any_of and between . Or any other alternatives? 回答1: queryable.any_of( queryable.between(:average_nightly_min_price, [10,100]).selector, queryable.between(:average_nightly_max_price, [110,1100]).selector ) It does not work if the queryable is embeded. For ruby versions prior 2.0: queryable.any_of( queryable

mongodb mongoid-rails unable to increment counters in a hash in embedded document

风流意气都作罢 提交于 2019-12-13 16:45:34
问题 I am using Mongoid 4.0.2 , Rails 4.2.1 amd Mongodb 2.4.8. I have daily_events as an embedded document in person collection as shown below. class Person include Mongoid::Document field :email, type: String field :month, type: Date field :monthly_total, type: Hash, default: {:email_open => 0, :email_click => 0, :page_view => 0} embeds_many :daily_events end class DailyEvent include Mongoid::Document field :name, type: String field :day_1, type: Hash, default: -> {:email_open => 0, :email_click

Mongoid 4: like query on integer column

那年仲夏 提交于 2019-12-11 09:29:44
问题 I need a mongoid search like query with INTEGER COLUMN . For example: SELECT * FROM users WHERE mobile LIKE '%9980%'; Here is the my model: class User include Mongoid::Document include Mongoid::Timestamps ## # Columns field :name, type: String field :mobile, type: Integer end I already tried following examples. But no luck :( User.where(:$where => "/^#{params[:mobile]}/") User.any_of({mobile: /.*#{params[:mobile]}.*/i}) User.where(mobile: /8801/)) How to write it with mongoid? 回答1: Try this

setting mongoid hash field values

做~自己de王妃 提交于 2019-12-05 01:07:06
I'm using Mongoid in a Rails project (both 4.0.x), and I've got a document with a hash field that stores some schema-less data. class Thing field :name, type: String field :mass, type: Integer field :info, type: Hash end With this setup, I can query for things, say, that have a key :endDate like so: Thing.where("info.endDate"=>{'$exists'=>true}) And that's all nice and handy. Using a hash field for this :info field is nice because what I want to store doesn't have a fixed schema and varies from one thing to another. Ok, but, I can't use the same dot syntax to $set key/value pairs in the :info