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 connection pool on heroku

I have an application deployed on heroku. Sometimes background process raises the following error: "The task failed because of an error: could not obtain connection within 5.0 seconds. The max pool size is currently 1; consider increasing the pool…
luacassus
  • 6,540
  • 2
  • 40
  • 58
2
votes
1 answer

how to reset all invalid fields of a mongoid document?

I have a mongoid document (in a rails app) that has failed validation. I want to reset all of the invalid fields. Currently I am doing this: @product.errors.each do |e,m| method_name = "reset_#{e}!" @product.send(method_name) end This is ok,…
nashape
  • 733
  • 9
  • 13
2
votes
0 answers

to_json is slow when using the :include option for mongoid

For example, I have two documents class Task include Mongoid::Document field :name, type: String belongs_to :person end and class Person include Mongoid::Document field :name, type: String has_one :stage end and I have a method in my…
Robin Rosicky
  • 325
  • 4
  • 9
2
votes
1 answer

received :update_attributes with unexpected arguments

I am very new to rspec and factory girl and I am stuck with a strange problem. I have an action in a controller like: def update @property = current_user.properties.find params[:fee][:property_id] @fee =…
Asnad Atta
  • 3,855
  • 1
  • 32
  • 49
2
votes
3 answers

Searching on two conditions in MongoDB in Ruby on Rails

I am using rails cast video http://railscasts.com/episodes/240-search-sort-paginate-with-ajax . I have to use two conditions to search in my database. # In my form for search <%= form_tag products_path, :method => 'get', :id => "products_search"…
regmiprem
  • 735
  • 2
  • 14
  • 41
2
votes
1 answer

mongoid_fulltext utf-8 special characters

I'm building a small rails 3 app using mongodb (and mongoid) for my database. I am using the mongoid_fulltext gem (https://github.com/aaw/mongoid_fulltext) to make my database searchable, which has worked fine so far. However, I just tried testing…
asprotte
  • 1,081
  • 1
  • 9
  • 12
2
votes
1 answer

Reducing DB calls when using RABL with mongoid

I have a few scenarios where I would like to do as little DB calls as much as possible via eager loading, but I have not been able to do it well. Given the 2 scenarios below, how can i change my RABL to do as little calls as possible? OBJECT…
meow
  • 27,476
  • 33
  • 116
  • 177
2
votes
1 answer

How to configure mongoid for development and staging environments properly?

I had create two environment for development on local machine and staging on heroku. Here my 'mongoid.yml': development: sessions: default: database: mydb_development hosts: - localhost:27017 staging: sessions: …
Denis Kreshikhin
  • 8,856
  • 9
  • 52
  • 84
2
votes
1 answer

in Mongoid 3, can I build a Queryable and then pass it to a where method?

The docs between Origin and Mongoid aren't really clear on how to use a Origin::Queryable object. Can I build a Origin::Queryable object up and then pass it to a ModelName.where method? It seems that I can't but on the other hand, seems like a…
jcollum
  • 43,623
  • 55
  • 191
  • 321
2
votes
2 answers

Mongoid equivalent of ActiveRecord's `first_or_initialize`

I was just wondering if someone knew the mongoid equivalent of rails' activerecord-query-interface method first_or_initialize. How do I implement the same functionality in Mongoid?
arvindravi
  • 53
  • 1
  • 4
2
votes
1 answer

Adding custom fields to a class at runtime, in Ruby with mongoid

In a project came across a requirement wherein a logged in user should be asked specific data based on his company. This specific data would be company specific, and could be mandatory or unique. This is the approach I took. 1. Defined a model to…
RoRRe
  • 291
  • 2
  • 10
2
votes
0 answers

undefined method 'map' for nil class

I'm a newbie and I got some trouble when run rails 3 server with mongodb (using mongoid) in production mode. Everything is ok in development mode, and I cannot figure out what am I missing. Please help me, thank you very much. This is the…
2
votes
0 answers

how to serve .swf flash files with static links using rails - asset pipeline or not? using mongoid

Scenario The rails application is running mongoid. For every instance in the below model, there's a portfolio field which needs to be a .swf flash file. class Person include Mongoid::Document field :name, type: String field :skill,…
qwexar
  • 303
  • 5
  • 16
2
votes
1 answer

Rails: How to model objects with a mix of both fixed and dynamic data

I am building a site with a database of users. I am using arbor.js to build a graph for each user. The graph is a tree-like structure with edges and nodes that looks something like this (I had an image ready to go but apparently don't have enough…
Logan
  • 165
  • 1
  • 7
2
votes
1 answer

Returning distance from query point with nearSphere

I'm trying to query my collection using geoSpatial query to return results near to a point, along with the distance from that point. I'm using Queryable#near_sphere with Mongoid http://mongoid.org/en/origin/docs/selection.html This executes the…
Alex
  • 37,502
  • 51
  • 204
  • 332