Questions tagged [mongoid]

Mongoid is the official Ruby Object-Document-Mapper (ODM) for MongoDB.

Mongoid (pronounced mann-goyd) is an Object-Document-Mapper (ODM) for MongoDB written in Ruby. Mongoid as of version 5 is under the control and guidance of MongoDB as the official Ruby ODM.

The philosophy of Mongoid is to provide a familiar API to Ruby developers who have been using Active Record or Data Mapper, while leveraging the power of MongoDB's schema-less and performant document-based design, dynamic queries, and atomic modifier operations.

4728 questions
2
votes
0 answers

Mongoid presence_of embedded document and destroy embedded

I have some mongoid document: class Firm include Mongoid::Document embeds_many :offices validates_presence_of :offices end At least one office must be present. It works. However when 'destroy' method called for latest office than firm was…
Dmitry Dedov
  • 1,106
  • 7
  • 15
2
votes
1 answer

Mongoid: has_many relation with alias

BACKGROUND: I have a Team model which has_many Players, which allows for one to call @team.players and receive a Mongoid::Relations::Targets::Enumerable list of Players back. OBJECTIVE: I'd like to also be able to retrieve a list of players at a…
neon
  • 2,811
  • 6
  • 30
  • 44
2
votes
1 answer

Mongoid + ActiveModel validation + I18n, not properly translating attributes

I am trying to internationalize the attributes of my Booking model From my fr.yml : attributes: &attributes booking: first_name: 'Prénom' last_name: 'Nom' email: "Email" phone: 'Téléphone' activemodel: errors: …
Intrepidd
  • 19,772
  • 6
  • 55
  • 63
2
votes
0 answers

Rails and MongoID webapp can't save data

I have a ruby on rails webapp hosted at digitalocean which stores its data on a mongo db through mongoID. I'm importing some data through a common API on a sidekiq worker but then I try to create an object like: array_of_consumptions =…
jpgbarbosa
  • 780
  • 4
  • 14
2
votes
2 answers

workaround for polymorphic habtm in mongoid?

I was wondering if someone could help me model the below scenario. I have a User class, an Event class and a Venue class in Mongoid. I would like for users to be admins of either an Event or a Venue or both. These different roles could end up…
jdkealy
  • 4,807
  • 6
  • 34
  • 56
2
votes
1 answer

mongoid and kaminari throws undefined method page

When using kaminari with mongoid, I get the error undefined method `page' for # Not sure what is wrong. I even tried running Item.page(params[:page]) and I get the error NoMethodError: undefined method…
Amit
  • 3,952
  • 7
  • 46
  • 80
2
votes
0 answers

Database items not available when running RSpec and Mongoid

I'm new to Rails so probably I'm missing something obvoius... I'm trying to write a Rails app that uses Mongodb with the Mongoid gem. I have some troubles with testing. I want to check if an html table generated from db content is correct. I'm…
Mir
  • 1,575
  • 1
  • 18
  • 31
2
votes
1 answer

Mongoid dynamic query

This must be an easy one, but I'm stuck... So I'm using Rails#3 with Mongoid and want to dynamically build query that would depend upon passed parameters and then execute find(). Something like def select_posts query = :all # pseudo-code here …
xaxa
  • 1,057
  • 1
  • 24
  • 53
2
votes
2 answers

Mongoid with Parent References is null

I'm trying to do Model Tree Structures with Parent References using Mongoid, but the parent is set to null. This is my class: class Category include Mongoid::Document field :name, type: String belongs_to :parent, :class_name =>…
Roei
  • 319
  • 4
  • 15
2
votes
2 answers

Heroku rails queuing mongoid

I need to proccess a csv file with 10,000 records in it. It takes about 4 seconds per 100 records, and I'm cool with it. I want to be able to split the 10,000 record to 100 jobs, that will be executed when server is not busy(no order needed). I'm…
Chen Kinnrot
  • 20,609
  • 17
  • 79
  • 141
2
votes
1 answer

Mongoid 3.1.0 CounterCache doesn't work

I'm trying to use Mongoid CounterCache but it doesn't work. I tried to just use belongs_to :user, counter_cache: true But it returns Problem: Invalid option :counter_cache provided to relation :user. Summary: Mongoid checks the options that are…
Seif Sallam
  • 821
  • 2
  • 10
  • 30
2
votes
1 answer

Mongoid query by reference attribute

here is a simple structure: class Dinner belongs_to :user field :name class User has_many :dinners field :name now, what i want is to find all the dinners hosted by 'John'. looking for something like: Dinner.where('user.name' =>…
Sagiv Ofek
  • 25,190
  • 8
  • 60
  • 55
2
votes
0 answers

Can we define cancan's ability with associations in mongoid

I'm trying to define an ability: # customer.rb class Customer include Mongoid::Document has_many :accounts end class Account include Mongoid::Document belongs_to :site end # ability.rb can :manage, Customer, accounts: { :site_id.in =>…
Samnang
  • 5,536
  • 6
  • 35
  • 47
2
votes
3 answers

Using a jquery datepicker with a Rails MongoId Date field results in a "argument out of range" error

I'm trying to render a Date field for my rails model as a datepicker. The model looks like: class Appointment include Mongoid::Document field :date, type: Date end _form.html.haml view looks like: = form_for @appointment, :url => {:action =>…
Oved D
  • 7,132
  • 10
  • 47
  • 69
2
votes
1 answer

mongoid random from controller

is It possible get a shuffle/random of a collection from action in controller. def action #pseudocode something like the next: @objects = Object.random respond_to do |format| format.html end end I now can get shuffle from my view, with: <%…
hyperrjas
  • 10,666
  • 25
  • 99
  • 198