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

How do you seed relationships for Mongoid in Ruby on Rails?

I'm trying to create a small game server using Ruby on Rails, Mongo, with Mongoid as the ORM, with Devise for authentication. I'm trying to modify the db/seeds.rb to seed several users and game documents. How do you create a seed between two…
Dominic Tancredi
  • 41,134
  • 7
  • 34
  • 50
2
votes
1 answer

mongoid convert has_many relation into embeds_many

I made the early novice-mongodb mistake awhile back and make a lot of has_many relations when I should have been embedding them. My question is how can I now convert my records from a polymorphic has_many scenario to embeds_many? #Place.rb has_many…
ere
  • 1,739
  • 3
  • 19
  • 41
2
votes
1 answer

when associations should be embedded or referenced Mongodb

I am using mongodb in my rails app with odm mongoid My questions are easy: a) when associations between objects should be embedded or referenced? b) how does this affect the application performance? Thank you very much!
hyperrjas
  • 10,666
  • 25
  • 99
  • 198
2
votes
2 answers

Sinatra, Mongoid, Heroku, MongoHQ: connecting to Mongodb

Trying to get Mongoid up and running with Sinatra on Heroku (MongoHQ). Previous experience with Rails but first time with the stack and Sinatra. Started with one of the simple examples on the web (app.rb): require 'rubygems' require…
Daniel May
  • 2,192
  • 5
  • 25
  • 43
2
votes
1 answer

Recursive Embedding & Mongoid - Parent doesn't save

I'm slowly getting crazy with this problem. I'm pretty sure it is something trivial and I have misunderstood something as I am just beginning my journey with Mongoid (and Ruby on Rails). My model is the following: class Drawing include…
Mathieu
  • 622
  • 1
  • 6
  • 12
2
votes
1 answer

Mongoid 3 - access map_reduce results

In mongoid 2, this used to work: mr_collection = self.collection.map_reduce(map, reduce, { :query => query, :finalize => finalize, :out => {:replace => 'mr_results'} }) limit = (options[:limit] || 10) skip = (options[:skip].to_i || nil) page…
Daly
  • 51
  • 7
2
votes
1 answer

How to perform a geo search inside the difference of two circles in MongoDB=

Is it possible to perform a geospatial search in MongoDB in the resulting area from the difference of two circles. Let's say that I have a circle A of radius x and another circle B of radius y where y > x. I need to find all the points that are…
GuidoMB
  • 2,191
  • 3
  • 25
  • 40
2
votes
1 answer

Sorting by two fields mongoid

I have an object Report that contains two integer fields: Month and Year. I need to sort it by "date" Report.desc(:year).desc(:month).each do |a| puts a.year.to_s + " " + a.month.to_s end results: 2011 12 2011 11 2012 7 2012 6 2012 5 2012 4 2012…
Benjamin Harel
  • 2,906
  • 3
  • 24
  • 32
2
votes
2 answers

Retrieving sublist 3 level deep in Rails

I have a datamodel that contains a Project, which contains a list of Suggestions, and each Suggestion is created by a User. Is there a way that I can create a list of all distinct Users that made Suggestions within a Project? I'm using Mongoid 3. I…
netwire
  • 7,108
  • 12
  • 52
  • 86
2
votes
1 answer

can not save new record to my rails model using mongoid and MongoDB

Haven't change my code for some time, and it was working fine. But started yesterday, I found I can't save my new record to the mongod db via mongoid. Background: gem 'rails', '3.2.5' gem 'mongo', "1.6.2" gem "mongoid", "2.4.7" mongo server…
Guoqiang Huang
  • 169
  • 2
  • 10
2
votes
1 answer

Mongoid 3.0 embedded 1-N query for listing all embedded fields

Suppose an Embedded 1-N model like the following : class Band include Mongoid::Document field :group_name embeds_many :albums end class Album include Mongoid::Document field :name field :sold embedded_in :band end How can I get a…
Luca G. Soave
  • 12,271
  • 12
  • 58
  • 109
2
votes
1 answer

Changing mongoid embeds_many association name

Using Rails 3.2, and Mongoid 2.4. I have a legacy model, Organization, that embeds_many organization_members. It looks something like this: class Organization include Mongoid::Document embeds_many :organization_members end class…
Glenn
  • 1,092
  • 1
  • 10
  • 22
2
votes
2 answers

How to configure rspec & mongoid for gem testing?

I am working on creating a new Gem that has some models which use Mongoid. I would like to test my gem using RSpec. I have started using RSpec for writing tests. I have installed a gem called mongoid-rspec and set it up according to its…
Andrew
  • 227,796
  • 193
  • 515
  • 708
2
votes
1 answer

Building embedded mongoid documents in form

I might be missing something silly but I can't get multiple embedded photo files into a form Models class Product include Mongoid::Document embeds_many :photos, cascade_callbacks: true end class Photo include Mongoid::Document …
Jeff Locke
  • 617
  • 1
  • 6
  • 17
2
votes
2 answers

MongoDB - Transfer Data one Collection to Another Collection

I need to know how we can transfer the data or records from one collection to another collection in MongoDB and same time whether we can use "find()" condition while transferring the data from one to another collection. If knows, share the details…
Kumaran
  • 219
  • 5
  • 17