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
0
votes
2 answers

Implementing has_many_through & polymorphic association in Mongoid

I have 4 models, User(Postgres), Subscription(Mongo), Podcast (Mongo), and Newspaper (Mongo). A user can have multiple podcasts through subscriptions and a podcast can have multiple users through subscription. A subscription also has fees field with…
0
votes
1 answer

Calling .attributes on model object avoid fileds with nil values

When attributes() is called on a Mongoid model object it excludes the fields with nil values, is there a way to get all the fields irrespective of their values? media = Media.first media.attributes #=> ignores nil values Also, FYI this happens…
Rajdeep Singh
  • 17,621
  • 6
  • 53
  • 78
0
votes
1 answer

Warning on updating Mongoid Gem to Version 5 Issue

I have updated the mongoid gem to 5 from mongoid-4 on rails 4 application. I am facing the following warning on app restart W, [2017-02-15T13:59:49.356541 #14483] WARN -- : MONGODB Unsupported client option 'max_retries'. It will be ignored. W,…
tessie
  • 964
  • 3
  • 14
  • 24
0
votes
1 answer

Mongoid not saving hash property

I'm using Rails 4 and Mongoid 4. In my app I have a model I have a hash attribute. I'm trying to update this attribute like so: user = User.find(id) user['hash_attr']['another_attr'] = another_hash user.save But the above code doesn't seem to get…
WagnerMatosUK
  • 4,309
  • 7
  • 56
  • 95
0
votes
1 answer

How to find all document by association Mongoid 4

I have a model Tag which potentially belongs to several other models, but at the moment only one model Todo which in turn belongs to User like so: class User include Mongoid::Document field: name, type: String has_many :todos end class Todo …
WagnerMatosUK
  • 4,309
  • 7
  • 56
  • 95
0
votes
1 answer

Mongoid after save call back runs twice

class SubJob field :total_qty end class Part belongs_to :sub_job after_save :update_inventory, if: ready_for_invoice after_save :update_total_qty def update_inventory # creating one more part2 part2 =…
Siva Gollapalli
  • 626
  • 6
  • 20
0
votes
1 answer

Filter nested attributes with ruby mongoid gem

I have define the scope below (within my model) to help me filter out certain un-required nested data. scope :active_inactive, -> { self.in({ state: ["current"], "events.type" => [ :active, :inactive, ] …
Ikenna
  • 989
  • 4
  • 12
  • 24
0
votes
0 answers

Mongoid query to get all parent documents where at least one of the embedded documents matches the condition

I have these questions documents in mongodb, and it can have multiple answers documents embedded in it. I am using mongoid in rails app. { "_id" : ObjectId("5642993541021327d3000004"), "asked_to" : [ "5642978841021327d3000000", …
JVK
  • 3,782
  • 8
  • 43
  • 67
0
votes
1 answer

Date is not working in rails application with mongo id

I have create an rails application with mongoid but im facing one problem at DATE I created an scaffold with a name "posting" When im editing date it will updated.... I follow the instruction of Railscast #238 Mongoid here there is my posting.rb…
Nani
  • 446
  • 7
  • 24
0
votes
1 answer

MongoDB select documents based on multiple fields

Let's say we have the following documents in a collection: { "_id" : ObjectId("55aa9d35dccf57b64d34f448"), "a" : 1, "b" : 7, "c" : 0 } { "_id" : ObjectId("55aa9d64dccf57b64d34f449"), "a" : 2, "b" : 8, "c" : 1 } { …
xx77aBs
  • 4,678
  • 9
  • 53
  • 77
0
votes
1 answer

mongoid scope find the wrong conversation

I have the following scope on my model: scope :between, -> (sender_id,recipient_id) do where(sender_id: sender_id, recipient_id: recipient_id).or(sender_id: recipient_id, recipient_id: sender_id).exists? end this try to find the conversation…
Jean
  • 5,201
  • 11
  • 51
  • 87
0
votes
1 answer

Rails check for duplicate models

I did a mistake in my rails app, and I didn't enforce the uniqueness of logins. Now I'd like to clean this mess by finding and removing duplicates (manually) in my code. Is there a nice command I could enter in the Rails console that would let me…
Cyril Duchon-Doris
  • 12,964
  • 9
  • 77
  • 164
0
votes
1 answer

Need help for setting association from multiple tables Rails4 mongoId

I have issue with setting association here while a Teacher sets his/her availability. A teacher can only set availability against the courses he/she is registered for. List of Courses in pre-defined from CourseType table. At time of teacher…
0
votes
1 answer

How to get all embedded mongoid documents for a user

In Mongoid (Rails) I have 3 models: File, Version and User. Version is embedded_in File, and both File and Version belongs_to a User (though not necessarily the same for all Versions in a File). Now I want to retrieve all Versions that either belong…
Jan
  • 993
  • 1
  • 13
  • 28
0
votes
1 answer

Rails nested models optimised query

EDIT : I'm using Mongoid, so no chaining nor has_many through: I am developing a backend for project administration, and I have "deeply" related models class Project include Mongoid::Document has_many :steps scope :active, ... class Step …
Cyril Duchon-Doris
  • 12,964
  • 9
  • 77
  • 164