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
1
vote
1 answer

mongoid-4 how to validate uniqueness of belongs_to in 1 to 1 association

I have a 1-to-1 association between 2 mongoid models and I keep getting duplicates, that is having more than one child record(card) with same parent_id(that is user). I have tried validating uniqueness of the belongs_to association has shown below,…
brg
  • 3,915
  • 8
  • 37
  • 66
1
vote
1 answer

How to retrieve a mongoid document _id after it was persisted?

Sorry if it's trivial, but I can't find an answer, so maybe I don't know how to ask the question. I have a simple case: I do: SomeMongoidObject.new.save And after that I want to use the id of new object to start a new background worker process. I…
alobodzk
  • 1,284
  • 2
  • 15
  • 27
1
vote
1 answer

How do I pass secret keys into mongoid.yml using secrets.yml in Rails 4.2?

This is my first time using Mongoid, everything works fine in test/local server, but I am hitting a wall when it comes to deploying into IBM Bluemix (Don't ask me why Bluemix, I know it is probably easier if I deploy to Heroku using Figaro.) I am…
Bill Chau
  • 13
  • 2
1
vote
0 answers

Mongoid - Query nested objects and match with array

My models class Person embeds_many :skills, class_name: "PersonSkill" class Project embeds_many :skills, class_name: "ProjectSkill" class Skill belongs_to :tag # Tag class is irrelevant for my question I think field :tag_name # Assume it's…
Cyril Duchon-Doris
  • 12,964
  • 9
  • 77
  • 164
1
vote
1 answer

How to resolve "not authorized for query on db.users" Mongoid

I've created a new Rails app using Rails 4 and Mongoid 4. I'm getting this error "not authorized for query on mydb.users" when I run my test: RSpec.describe User, type: :model do it "is invalid without a name" do user = User.new(name:…
WagnerMatosUK
  • 4,309
  • 7
  • 56
  • 95
1
vote
1 answer

Querying for last 7 or 30 days date range with mongodb mongoid rails

I am using Mongodb 2.4.8, Mongoid 4.0.2 and Rails 4.2.1 I have been trying to get a date range query ran through mongoid to return the right set of results on a test data with mongodb. I created just 6 documents spanning over 5 - 7 days period. For…
brg
  • 3,915
  • 8
  • 37
  • 66
1
vote
2 answers

Mongoid Search by Array of Association Id's

I have a Rails 4.2, Mongoid 4 project with these models: class Customer #aka Company include Mongoid::Document has_many :branches end class Branch include Mongoid::Document field :name, type: String, default: "" belongs_to…
Ryan K
  • 3,985
  • 4
  • 39
  • 42
1
vote
1 answer

Preventing Mongoid 4.0.0 model field coercion of id => _id

I'm using Mongoid 4.0.0 with Rails 4. My models map tables in another application, and I have no control over the field names. One of the models has a field named id, which is getting coerced into Mongo's _id field. For example, when I insert a…
RoUS
  • 1,888
  • 2
  • 14
  • 29
1
vote
1 answer

scope not working on Mongoid (undefined method `to_criteria')

I invoke ReleaseSchedule.next_release in other controller and got the following error NoMethodError (undefined method `to_criteria' for #): app/controllers/weekly_query_controller.rb:15:in…
newBike
  • 14,385
  • 29
  • 109
  • 192
1
vote
1 answer

mongoid validate uniqueness of each member in has_many or has_and_belongs_to_many relation

I have a model that is something similar to the following class Lecture include Mongoid::Document belongs_to :orgnization belongs_to :schedule has_one :lecturer validates :lecturer, presence: true, uniqueness: { scope: [:orgnization,…
a14m
  • 7,808
  • 8
  • 50
  • 67
1
vote
1 answer

Skip default scope for relation in mongoid

How can I skip the default scope for relations in mongoid? The trashable concern implements a soft-delete on the model, also it adds the following field :d_at, type: DateTime default_scope -> { where(d_at: nil) } If a brand gets trashed I…
Sander Visser
  • 4,144
  • 1
  • 31
  • 42
1
vote
1 answer

How to create model with an array field which contains another documents as an embedded documents in Mongodb (Mongoid)

I am using Rails 4 with Mongoid for an event based application. I am trying to create a model where I want to add an array field with embedded documents in that array. This embedded documents will contain user's geo coordinate and timestamp. After…
punkb
  • 53
  • 12
1
vote
3 answers

Mongoid 4: like query on integer column

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, …
Zeck
  • 6,433
  • 21
  • 71
  • 111
1
vote
1 answer

rails 4 f.fields_for doesn't iterate over my embedded collection

I am trying to build a simple application where user can post something and attach questions to the post (post.questions). I am getting problem displaying view in embeds_many scenario. Though I create multiple questions in PostsController # new…
r3doc
  • 69
  • 6
1
vote
0 answers

Unable to create correct Mongoid model from JSON

I'm trying to create a Mongoid model from the corresponding JSON structure. However it does not include the embedded relation frameworks. I'm using Mongoid 4.0. Am I doing something wrong or is this a bug? If I store any embedded relation via…
stefankolb
  • 328
  • 3
  • 16