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

mongoid where with has_many relation

I have 3 models City.rb has_many :places Place.rb has_many :reviews, as: :reviewable And Reviews which have an attribute state which I would like to be able to check. Review.rb belongs_to :reviewable, polymorphic: true state_machine :initial…
ere
  • 1,739
  • 3
  • 19
  • 41
2
votes
1 answer

rails_admin: browsing collections of unknown structure

I am trying to use rails_admin w/mongoid to show a tabular view of a mongo collection. The problem is that I do not know the structure of the objects in the collection beforehand. rails_admin, AFAIK, is based on the model definition. Is there any…
Joseph Tura
  • 6,290
  • 8
  • 47
  • 73
2
votes
1 answer

Access parent of has_many relationship

Is there a way to access the parent of a polymorphic model in Mongoid 3? I have this relationship class Project ... field "comments_count", :type => Integer, :default => 0 has_many :comments, :as => :commentable ... end class Comment ... …
netwire
  • 7,108
  • 12
  • 52
  • 86
2
votes
1 answer

Undefined method 'reject' when using mongoid-paperclip gem

The error I am getting NoMethodError (undefined method `reject' for #): app/controllers/photos_controller.rb:3:in `create' The form (it's in HAML) %form{:id => 'photo-upload-form', :method =>…
Cheenu Madan
  • 129
  • 12
2
votes
1 answer

Mongoid : IPv6 addresses storage

I need to store IPv6 addresses in a Mongodb database using Rails3 + Mongoid. There will also (mostly) be IPv4 addresses in the collection. I need addresses to be stored as decimals since I have to query for addresses that belongs to a network (I'll…
2
votes
0 answers

integration test on sign-in page with capybara, rspec, mongoid, database-cleaner

I am trying to setup login test for my web app. User should be redirected to dashboard after successful sign-in. However, in the dashboard spec, the user created by factory girl can't sign in. But if I use attr = Factory.attributes_for(:user) user…
2
votes
1 answer

how to set time zone for mongoid

I am using mongoid for my rails app. I want to set time zone for mongoid. I tried with this in application.rb config.mongoid.time_zone = 'Kolkata' but no luck. I also tried with this use_utc: false use_activesupport_time_zone: true still it uses…
Harshal_m_joshi
  • 1,489
  • 1
  • 16
  • 27
2
votes
3 answers

Can one run Mongoid queries via the command line?

I am working within a Rails app that uses MongoDB and Mongoid. I can run mongo queries using the mongo shell environment, but I'd love to play with Mongoid in irb. Is that something that I can do? If so, could someone please tell me how? Thanks :)
Rebekah Waterbury
  • 22,236
  • 5
  • 23
  • 28
2
votes
1 answer

Mongo / Rails Mongoid index on embedded field

I'm getting something incredibly simple wrong, and not sure what I'm doing wrong. Fairly new to Mongo Using Rails 3.2.6 with MongoDB and Mongoid. Trying to add an index to an embedded field. I have a model 'Scheme', which has embedded 'Referals'.…
bobomoreno
  • 2,848
  • 5
  • 23
  • 42
2
votes
1 answer

Mongoid model that points to an AR model and vice versa?

Let us say we have following models in our app: # AR model class Foo < ActiveRecord::Base belongs_to :bars # this is an association pointing to a Mongoid model end # Mongoid model class Bar include Mongoid::Document belongs_to :foo # this…
Harish Shetty
  • 64,083
  • 21
  • 152
  • 198
2
votes
2 answers

MongoDB MapReduce on deep nested documents issue

For my Rails+MongoId application i need to aggregate data for statistical purposes. My model is rapresenting a general Web application that has_many versions (aka: bundles) and relative users activations: App = { "_id" :…
Mike Costa
  • 41
  • 4
2
votes
1 answer

Lazy loading the has_and_belongs_to_many field while using mongoid gem

I have the following models: class Foo has_and_belongs_to_many :bars end class Bar has_and_belongs_to_many :foos end Each document representing the Foo instance has an array field called bar_ids. When ever a Foo object is retrieved from the DB,…
Harish Shetty
  • 64,083
  • 21
  • 152
  • 198
2
votes
0 answers

Unable to perform queries on mongodb started with --auth switch in rails 3 with mongoid.

Simplified case: I create a new rails 3.2 project, without active record. I add mongoid 3.0.0.rc to the Gemfile and then rails g mongoid:config. I edit my mongoid.yml to look like the one I have posted below (except that hosts is now set to…
2
votes
1 answer

Why \xF3 is not recognized as UTF-8

I have this hash: a={"topic_id"=>60693, "urlkey"=>"innovacion", "name"=>"Innovaci\xF3n"} and I am trying to save it to MongoDB using Mongoid, when I get this error: BSON::InvalidStringEncoding: String not valid UTF-8 I am then trying to gsub…
Cacofonix
  • 465
  • 11
  • 19
2
votes
1 answer

Tracking history of a model and all the associated models to it in Rails

Recently in one of my projects I was required to add functionality to track all actions(create, update, delete), redo and undo to some models. In the project I am using Mongoid as a ODM. I can add most of these functionalities with mongoid-history.…
hers19
  • 146
  • 2
  • 6