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

Why can't I push duplicate records using has_many in Mongoid?

Why can't I push a record multiple times when using has_many? class Template include Mongoid::Document has_and_belongs_to_many :widgets, inverse_of: nil Attempt to add duplicates: (rdb:387)…
Jeremy Smith
  • 14,727
  • 19
  • 67
  • 114
1
vote
2 answers

How do you update all embedded documents for a specific column in a table in Mongoid?

Currently I have an address column that is an embedded document in my users table. The address column contains the _id for related rows in the address table. Each user can have many addresses so there can be multiple embedded documents in the user…
Goalie
  • 3,045
  • 5
  • 35
  • 46
1
vote
1 answer

User ranking with rails3 and mongodb

I am trying to implement user ranking with mongodb. So user has two fields: field :score, type: Integer, :default => 0 field :solution_count, type: Integer, :default => 0 and to list all the users in the score table one can easily do smth like…
makaroni4
  • 2,281
  • 1
  • 18
  • 26
1
vote
1 answer

rails 3.2 to_date monkey patching & Mongoid

I have put a small monkey patch to allow for better String.to_date handling. It works great on strings but it seems mongoid has its own method for trying to convert the string into a date. I am doing this because ruby expects a "DD/MM/YY" where my…
Jason Waldrip
  • 5,038
  • 8
  • 36
  • 59
1
vote
1 answer

Looping through all the records and changing them in between

Im just a bit curious as to what would happen in this scenario (My setup is a MongoDB, Ruby on Rails via MongoID) Models.all.each do |model| model.destroy #delete the record newmodel = model.new #make a new record …
Tarang
  • 75,157
  • 39
  • 215
  • 276
1
vote
1 answer

Translating mongoid to german

I got a problem to translate the default validation messages in mongoid. I create a /config/initializers/mongoid.rb with Mongoid.add_language("de") http://mongoid.org/docs/installation/languages.html But every call on a validated field i got…
bulleric
  • 2,077
  • 6
  • 21
  • 36
1
vote
1 answer

Scaffold and Array type column

I have created model, controller and view with rails scaffold generator: rails g scaffold Todo description:string tags:array So I have the model: class Todo include Mongoid::Document field :description, :type => String field :tags, :type =>…
ceth
  • 44,198
  • 62
  • 180
  • 289
1
vote
1 answer

rails 3 mongoid and countries gem

I'd like to use the countries gem I found here instead creating a separate model. It works fine to inherit from but I'd also like to be able to have other classes belong_to it. Is this possible? IE something like below. Is there some method I…
ere
  • 1,739
  • 3
  • 19
  • 41
1
vote
1 answer

ActiveRecord::ConnectionNotEstablished (ActiveRecord::ConnectionNotEstablished)

I have a Rails application that works with mongodb. I want to deploy it to Heroku, but get the error: Using sass-rails (3.2.5) Installing sqlite3 (1.3.5) with native extensions Unfortunately, a fatal error has occurred. Please report…
ceth
  • 44,198
  • 62
  • 180
  • 289
1
vote
0 answers

Error Deploying to Heroku with Rails 3.2.1 / Mongoid

Similar to this question I'm having problems with deploying to Heroku on Rails 3.2.1 (Ruby 1.9.3-p125 - although I did set up Heroku to run with Ruby 1.9.3-p0). I followed all the steps in the Rails apps tutorial but my app is crashing when I try to…
ralphos
  • 626
  • 2
  • 10
  • 20
1
vote
1 answer

How to calculate and use latest updated object in Ruby on Rails?

I have Projelements, which are like: Milestone Task ... etc ... Each Projelement can have one or more embedded Comments (thanks to Mongoid). I want to be able to easily say: Give me a list of Projelements sorted by when they were last…
Daniel May
  • 2,192
  • 5
  • 25
  • 43
1
vote
1 answer

Mongoid not saving nested_attributes for 'belongs_to' in a 1:1 relationship

I have two model's Contact, and User. When I create a new user I am trying to create the contact at the same time. But It is not getting created for some reason. Any ideas on why? class Contact include Mongoid::Document include…
Jason Waldrip
  • 5,038
  • 8
  • 36
  • 59
1
vote
2 answers

Mongoid: search an array

Is it currently possible to search an array of BSON::OrderedHashes with Mongoid based objects? One of my attributes, let's call it foo in the bar class, looks something like the following: [#
randombits
  • 47,058
  • 76
  • 251
  • 433
1
vote
1 answer

Get objects size between relative dates

I have many User objects with created_at attribute e.g. I get objects with @users = User.all I want get the count of User objects with various ages from creation with @users.size for these date ranges: yesterday last week last month last…
hyperrjas
  • 10,666
  • 25
  • 99
  • 198
1
vote
0 answers

NoMethodError (undefined method `gsub' for []:Array):

I have the next model with a array field: Class Invitation include Mongoid::Document include Mongoid::Timestamps::Created include Sunspot::Mongo # this is the relation. Is not a field has_many :recipients, :class_name => 'Invitation',…
hyperrjas
  • 10,666
  • 25
  • 99
  • 198