mongoid

Using embeds on a child association to improve performance of sorting?

我怕爱的太早我们不能终老 提交于 2020-01-05 06:49:09
问题 I have a contact and a lead. They are completely two independent models. I have a leads page where I can query against leads, sort by leads and do other work on leads. Also, a contact can be created without a lead. However, a contact can has_one lead. So I set up my models like so: class Contact include Mongoid::Document has_one :lead field :reference_number field :some_date end class Lead include Mongoid::Document belongs_to :contact field :status end Here is the problem. On the leads page,

Where is the have_fields RSpec matcher defined?

拈花ヽ惹草 提交于 2020-01-05 05:45:07
问题 A recent question on using rspec featured some code with a have_fields matcher in it. A search indicated that have_fields was referenced in the mongoid-rspec gem, but when I went to GitHub, I could only find it referenced in the spec files. Similar searches of RSpec core and related gems came up empty as well. 回答1: You might be looking for the mongoid-minitest gem. In have_field.rb it declares have_fields as an alias: module Mongoid module Matchers module Document # TODO: Add documentation.

Mongoid not playing nicely with factories

你离开我真会死。 提交于 2020-01-05 04:57:17
问题 Moingoid doesn't seem to be setting embedded relationships persistently during my tests. In my user model I have: def vote_on(bill, value) if my_groups = self.groups my_groups.each do |g| bill.votes.create(:value => value, :user_id => self.id, :group_id => g.id) # result only with factories: bill.votes.first.group = nil # and bill.votes.first.user = nil !! # self.id and g.id have good values during the test, they just aren't persisting end else raise "no groups for this user" # #{self.full

Issues with rails4 and mongoid on production mode

ε祈祈猫儿з 提交于 2020-01-04 16:58:54
问题 I am working with rails 4.2.x and Mongoid . I am getting the following error when I try to run server in production mode ,but it runs smoothly on development mode, not sure why I am getting this error . I tried precomipling asses but no luck. => Booting Thin => Rails 4.2.1 application starting in production on http://localhost:3000 => Run `rails server -h` for more startup options => Ctrl-C to shutdown server Exiting /home/ratnakar/.rvm/gems/ruby-2.1.5@glimpse/gems/actionview-4.2.1/lib/action

Mongoid::Versioning - how to check previous versions?

余生长醉 提交于 2020-01-04 15:29:39
问题 I include the Mongoid::Versioning module in my Mongoid based class. What's the best way to check the previous 'version' or incarnation of a document? I want to be able to see its history. This can be either through rails console or MongoDB shell. What's the most easiest way to view the document history? 回答1: The Mongoid::Versioning module adds a field named version of type Integer to the document, that field records the version of the current document, starting at 1, up to the maximum (if

Having an error with nested forms with Mongoid

坚强是说给别人听的谎言 提交于 2020-01-03 06:27:40
问题 I am using Mongoid on Rails 3 and trying to build a nested form. The problem I run into is when I used accept_nested_attributes_for method, I get this error message: undefined method `persisted?' for []:Array Is anyone else having problem with nested forms in Mongoid? What can I do to fix it? Edit: more about the error. This is the full trace. mongoid (2.0.0.beta.19) lib/mongoid/criteria.rb:156:in `send' mongoid (2.0.0.beta.19) lib/mongoid/criteria.rb:156:in `method_missing' mongoid (2.0.0

What is the proper way to use namespaces and reference models inheriting from other (mongoid/rails)?

依然范特西╮ 提交于 2020-01-02 14:31:42
问题 I have the model HandlingScenario who inherits from Scenario . Like this: ## models/scenario.rb class Scenario include Mongoid::Document end ## models/scenarios/handling_scenario.rb class Scenarios::HandlingScenario < Scenario include Mongoid::Document belongs_to :user, :inverse_of => :handling_scenarios # In the `User` model, the reference is `has_many :handling_scenarios` end But when I try to access the HandlingScenario class, I get into trouble: ➜ rails c Loading development environment

Can I set Mongoid query timeout? Mongoid don't kill long time query

时光总嘲笑我的痴心妄想 提交于 2020-01-02 07:05:47
问题 Mongoid don't have timeout option. http://mongoid.org/en/mongoid/docs/installation.html I want Mongoid to kill long time queries. How can I set Mongoid query timeout? If I do nothing, Mongoid wait a long time like the below. mongo > db.currentOp() { "opid" : 34973, "active" : true, "secs_running" : 1317, // <- too long! "op" : "query", "ns" : "db_name.collection_name", "query" : { "$msg" : "query not recording (too large)" }, "client" : "123.456.789.123:46529", "desc" : "conn42", "threadId" :

Ruby/rails: mongoid with mongo(gem); a bson conflict? How to handle different versions?

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-02 06:57:26
问题 How to handle gem version mis-matches? Mongoid 4.0.0 (latest) uses moped (2.0.0) which requires bson 2.3 Mongo 1.10.2 (latest) uses bson 1.10.2 I can't use mongoid 4.0.0 and mongo 1.10.2 together, but I could in the past, when mongoid uses bson 1.x. Does anyone know how I can continue forward using both mongo and mongoid? -daniel Links: https://rubygems.org/gems/mongoid https://rubygems.org/gems/moped https://rubygems.org/gems/mongo 回答1: The latest unstable version 2.x (under heavy

rails environment mongoid connection issue

梦想的初衷 提交于 2020-01-02 06:28:31
问题 I have rails app 3.2.17, deployed in staging environment with unicorn 4.6.3 monitored by bluepill 0.0.66 using mongid 3.1.5 When I deploy for staging environment all works find including active_record except mongoid queries with result with following error: Error during failsafe response: Problem: No configuration could be found for a session named 'default'. Summary: When attempting to create the new session, Mongoid could not find a session configuration for the name: 'default'. This is