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

Validating polymorphic association type in Rails

I am developing a controller that creates a model with a polymorphic belongs_to association. What I do now to find the model it belongs to is as follows: def find_polymorphic_model(classes) classes_names = classes.map { |c| c.name.underscore +…
2
votes
2 answers

mongoid query - calling the size method produces an error

When I execute this query: User.where(:comments.size => 10) I am getting the following error: undefined method `size' for :comments:Symbol But according to the documentation here: http://mongoid.org/docs/querying/criteria.html This should be…
charleetm
  • 916
  • 1
  • 12
  • 26
2
votes
2 answers

How to handle Mongoid::Errors::DocumentNotFound in Rspec?

I have an ArticleController with the following code : def edit @article = current_user.articles.find(params[:id]) end And the following test: describe "GET 'edit'" do it "should fail when signed in and editing another user article" do …
Dominic Goulet
  • 7,983
  • 7
  • 28
  • 56
2
votes
1 answer

Mongodb: db_name must be a string or symbol

In my Rails 3.0.10 app, with Mongoid 2.2.2, I'm getting this error in production (works fine in development): .../gems/mongo-1.3.1/lib/mongo/util/support.rb:50:in `validate_db_name': db_name must be a string or symbol (TypeError) I've added this to…
bevanb
  • 8,201
  • 10
  • 53
  • 90
2
votes
1 answer

Concurrency and Mongoid

I'm currently trying my hand at developing a simple web based game using rails and Mongoid. I've ran into some concurrency issues that i'm not sure how to solve. The issue is i'm not sure how to atomically do a check and take an action based upon it…
EasyPush
  • 756
  • 4
  • 13
2
votes
1 answer

sort geonear search results in ruby on rails with mongoid

I am using below query to get search results Org.where('content.attribs.name'=>'cuisine', 'content.attribs.value'=>cuisine ).geo_near([lon,lat], :max_distance => dist, :spherical => true, num: num_results) now I want to sort these results by…
krishnareddy
  • 47
  • 1
  • 2
  • 6
2
votes
2 answers

Convert existing MongoDB string attribute to BSON::ObjectId

I have a collection of documents in MongoDB that has an attribute being stored as a string when it would work better if it was saved as BSON::ObjectId. The collection name is foo and the field is called bar. What's the best way to have every field…
randombits
  • 47,058
  • 76
  • 251
  • 433
2
votes
2 answers

Indexing mongoid

I've read the mongoid docs, but don't feel confident I properly understand how to index embedded documents correctly. Please take a look at this tiny code snippet and let me know if I am on the right track! Criteria temp =…
hcon
  • 21
  • 4
2
votes
1 answer

Error while reindexing solr with rails and mongodb

I am currently using mongodb in my rails application. I use mongoid as the ODM and I use sunspot_mongo. When I try reindex, I get the following error. >rake sunspot:reindex rake aborted! undefined method 'find_in_batches' for Article:Class I am…
Rahul
  • 44,892
  • 25
  • 73
  • 103
2
votes
2 answers

Mongo::OperationFailure repeatedly happening in EC2, what to do?

I am seeing a lot of exceptions in my log: A Mongo::OperationFailure occurred in foo#bar: Mongo::OperationFailure mongo (1.6.2) lib/mongo/util/tcp_socket.rb:76:in `read' I am using Mongoid as my Ruby driver. Not sure if this is related to…
randombits
  • 47,058
  • 76
  • 251
  • 433
2
votes
1 answer

Need group_by in a scope for Mongoid Document

I have a model like this: class Event include Mongoid::Document include Mongoid::Timestamps scope :range, lambda {|start, finish| where(:created_at => {'$gte' => start,'$lt' => finish}) if start && finish } end And I need a hash of…
Raphael
  • 1,701
  • 15
  • 26
2
votes
1 answer

How to benchmarking mongodb/mongoid scripts, for comparing two different query techniques

Do you have a suggestion on how to test performances over two different mongoid/mongodb query implementations? The implementation to compare, are related to a previous "Q & A" but I'll report those here again, for brevity : first code : Competitor …
Luca G. Soave
  • 12,271
  • 12
  • 58
  • 109
2
votes
1 answer

saving embedded documents mongoid

I have a person model which embeds_many addresses. Is there a way to always clear embedded relationship when updating? For example, If I send a complete representation of a person, including addresses, I want to replace existing addresses rather…
Tim Brunsmo
  • 581
  • 6
  • 22
1
vote
1 answer

How to validate image width and height on upload with carrierwave, mini magick and mongoid?

I need to check if the images people upload to my site have the exact width of 200px and height of 300px. If they haven't got those dimensions, they shouldn't be saved in the database. I've tried for ages with mini-magick and gone through numerous…
Holger Sindbaek
  • 2,278
  • 6
  • 41
  • 68
1
vote
2 answers

With mongo_session_store-rails3, session doesn't seem to work

I'm having a problem with sessions in rails 3.2 when I use mongoid as SessionStore. I decided to use Brian Hempel's fork of mongo_session_store gem, as it was updated last month. Before switching to this gem, I was using the default cookie-based…