Questions tagged [mongoid4]

Version 4 of Mongoid, an Object-Document-Mapper (ODM) for MongoDB with Ruby. Use this tag for questions relating to this specific version.

Version 4 of Mongoid (an Object-Document-Mapper (ODM) for MongoDB)), which is compatible with Rails 4. For a deeper description of Mongoid, see the main Mongoid tag.

Primary tag:

Homepage

104 questions
2
votes
0 answers

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

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…
brg
  • 3,915
  • 8
  • 37
  • 66
2
votes
1 answer

mongoid-history: undefined local variable or method `metadata' for

I am using rails 4, mongoid 4. I want to version my model with mongoid-history gem. This is my historyTracker file: class HistoryTracker include Mongoid::History::Tracker end This is initializer: Mongoid::History.tracker_class_name =…
zeitnot
  • 1,304
  • 12
  • 28
2
votes
0 answers

How to ignore an unknown subclass with single collection inheritance in Mongoid?

The default inheritance method for Mongoid is creating a single collection for all subclasses. For instance: class User include Mongoid::Document end class Admin < User end class Guest < User end Internally, Mongoid adds a _type field to each…
Guilherme Garnier
  • 2,208
  • 23
  • 22
2
votes
0 answers

Cannot generate mongoid config file in rails 4 engine

I've created a rails 4 engine and I am now trying to get it to run with Mongoid instead of active record. I am following the instructions on the official site so I have added s.add_dependency "mongoid", "~> 4.0.0" to the gemspec file, thanI ran…
Julien
  • 2,217
  • 2
  • 28
  • 49
2
votes
0 answers

No results querying mongoid with a boolean clause

I am having classes that implement module CanBePublished def self.included(o) o.class_eval do field :public, type: Boolean, default: false scope :published, -> { where(public: true) } end end end See what happens in a…
Jan
  • 6,532
  • 9
  • 37
  • 48
2
votes
0 answers

Duplicated has_many records using accepts_nested_attribute

Using Rails 4 and Mongoid 4 from master For some odd reason I am getting duplicated child records when a record fails validation (but not when it is valid) the form that then renders back to the user has the extra records in it I have a Pipeline,…
Jak Charlton
  • 231
  • 4
  • 9
2
votes
1 answer

Paperclip callback before_post_process not working in Rails4

I am working with Rails4 and mongoid-paperclip mongoid-paperclip (0.0.9) paperclip (>= 2.3.6) I wanted to change the file name, so my class is as below, class Icon include Mongoid::Document include Mongoid::Timestamps include…
RubyOnRails
  • 235
  • 1
  • 15
2
votes
1 answer

rails+mongoid validate dynamic attribute

I am using rails 4 + mongoid 4 beta1. Product belongs to Category and has dynamic attributes based on category. I validate dynamic attributes with custom method, but its looks ugly. How can i use standart validate methods inside my custom method or…
kolas
  • 754
  • 5
  • 16
2
votes
2 answers

Mongoid: How do I query for all object where the number of has_many object are > 0

I have a Gift model: class Gift include Mongoid::Document include Mongoid::Timestamps has_many :gift_units, :inverse_of => :gift end And I have a GiftUnit model: class GiftUnit include Mongoid::Document include Mongoid::Timestamps …
Cjoerg
  • 1,271
  • 3
  • 21
  • 63
1
vote
1 answer

How to avoid Mongoid (or MongoDB) replacing empty arrays with null

Background: I have built an API in Rails and a client in Angular. My API will connect to a third party API and grab some data. This data will come in as an nested object/hash which is stored in MongoDB/Mongoid. When my Angular clients manipulates…
WagnerMatosUK
  • 4,309
  • 7
  • 56
  • 95
1
vote
1 answer

Migrate from belong_to to has_and_belongs_to_many on mongoid without losing data

I'm using Rails 4.1 with mongoid 4.0 Currently, I have a relation 1-N class Tenant include Mongoid::Document belongs_to :tenant, index: true end class Experience include Mongoid::Document has_many :experiences, dependent: :nullify end I…
hcarreras
  • 4,442
  • 2
  • 23
  • 32
1
vote
1 answer

Error when seeding mongoDB thru heroku

Hello I have an app that I built on heroku and I can’t seem to get the mlab DB to work. It seems to connect but when I run heroku run rake db:setup I get an error and can’t see what it is. I upgraded to a paid account but that hasn’t fixed the…
SupremeA
  • 1,519
  • 3
  • 26
  • 43
1
vote
0 answers

Mongoid 4 #only or #without will now raise an error when attempting to save

I have some very large documents. Due to embedados and arrays fields. An example follows: { "_id" => BSON::ObjectId('5654b4b3204528cfa0000001'), "rating" => 0, "status" => :ok, "foo" => '...', "bar" => '...', # a few fields "group_ids"…
Iago
  • 308
  • 3
  • 9
1
vote
0 answers

Cancancan nested resource authorization fails with mongoid

Simply I explain it here. The question is how can I authorize nested resource with mongoid? Suppose that I have a Project model and a Project::Task model. Project has many Project::Task. I want to authorize Project::Task on controller level and do…
zeitnot
  • 1,304
  • 12
  • 28
1
vote
1 answer

How could I query by one of multiple possible value in mongoid

from = [:TPE, :TOKYO, :CHICHAGO] where( from: /.*#{from}.*/i, ) Input documents { from: 'PARIS' }, { from: 'PARIS' }, { from: 'TOKYO' }, { from: 'TPE' } Output documents { from: 'TOKYO' }, { from: 'TPE' }
newBike
  • 14,385
  • 29
  • 109
  • 192