mongomapper

How to organize my documents ?

Howdy guys, I'm pretty new to mongodb (only work with it for one small project) and I wanted to have your tips on how to organize my documents. My brain is not (yet) nosql formatted. I have a collection storing all kind of informations and I want to add tags to it. There will be 1-5 tags by document. I want to be able to search by tags ...

Not equals in mongo mapper

Hi there I'm trying to run a query where I want to ignore records with a certain email address... @foo = Bar.all(:email => 'xxx') <--- Except I want to negate where this email address exists. Please let me know how I can do it. Thanks! ...

MongoMapper Problems using Ruby Language

I installed mongo mapper gem and have the version 0.8.2. I opened the environment.rb file and editing it to use MongoMapper as shown below: # Be sure to restart your server when you modify this file # Specifies gem version of Rails to use when vendor/rails is not present RAILS_GEM_VERSION = '2.3.8' unless defined? RAILS_GEM_VERSION #...

Mongomapper documentation?

I have stumbled upon Mongoid which has great documentation: http://mongoid.org/docs/associations/ But I have heard that MongomMapper is de-facto for Rails. Where do I find API documentation for using Mongomapper? ...

Combine MongoDB and Postgresql in Rails?

Is it possible to combine AR with MongoMapper/MongoID? If so, are there tutorials/documentations for this? ...

How to keep "Cached Values" in Sync in MongoMapper-Model?

Hi together, at the moment I'm doing some tests with MongoMapper. When using relations, http://www.mongodb.org/display/DOCS/MongoDB+Data+Modeling+and+Rails sugests to use cached values where it fits... I take a stripped down example from there: class Story include MongoMapper::Document key :title, String key :url, Str...

Deleting EmbeddedDocuments with Mongo Mapper

I have mongo_mapper set up like so: class Person include MongoMapper::Document many :pets end class Pet include MongoMapper::EmbeddedDocument key :animal, String key :name, String key :colour, String end # Create a person me = Person.new # Add pets to the person me.pets << Pet.new(:animal => 'dog',:name => 'Mr. Woofs', ...

Eager Loading of Associations using MongoMapper

I'm looking to Eager Load Associated Documents using MongoMapper. Say I have an author with a :has_one condition to a Post, I should be able to load the author using a single query Post.find(:all, :include => :author) Any suggestions? ...

Ruby Sinatra - connect to mongoDB on mongoHQ failed

Hi all: This is just for my weekend project/study, I am very new to Sinatra and MongoDB. I've installed the gems for mongoDB, such as: mongo, mongo_mapper and mongoid. When I tried connecting to my database on MongoHQ from localhost, it encountered such an error: Mongo::ConnectionFailure at / failed to connect to any given host:port ...

Authentication for Rails 2.3.8 using MongoDB and mongo_mapper

Hi All, How will I do authentication using Rails 2.3.8 using MongoDB and mongo_mapper? Let me know your expert advise on this. By the way, a Rails noob here :) Thanks! ...

Where and how to do custom validation on models?

Lets say we have a simple model that stores two integers, the min and the max. We would like to force min <= max. class MinMax include MongoMapper::Document key :min, Integer key :max, Integer validate_presence_of :min, :max end 1) How would you validate that min is indeed equal or less than max? 2) If you don't think this ...

Why doesn't this test in the Diaspora app fail?

From http://github.com/diaspora/diaspora/blob/master/spec/models/profile_spec.rb describe Profile do before do @person = Factory.build(:person) end describe 'requirements' do it "should include a first name" do @person.profile = Factory.build(:profile,:first_name => nil) @person.profile.valid?.should be false ...

ERROR Errno::ECONNRESET: Connection reset by peer

gem 'rails', '3.0.0' gem 'devise' gem 'bson_ext', '>= 1.0.7' gem 'bson', '>= 1.0.7' gem 'mongo_mapper', :branch => 'rails3', :git => 'http://github.com/jnunemaker/mongomapper.git' gem 'devise-mongo_mapper', :git => 'git://github.com/collectiveidea/devise-mongo_mapper' With the above setup I get the following errors on requests: Starte...

Exception using MongoMapper with Ruby: "No file to load mongo_mapper"

I downloaded the mongo_mapper gem and it installed successfully. Now, I am using it in my app and it always throws exception "No file to load mongo_mapper". What is that supposed to mean? require 'mongo_mapper' include mongo UPDATE: After using require 'rubygems' first. My original problem is gone now there is another weird problem: ...

N+1 problem in mongoid

I'm using Mongoid to work with MongoDB in Rails. What I'm looking for is something like active record include. Currently I failed to find such method in mongoid orm. Anybody know how to solve this problem in mongoid or perhaps in mongomapper, which is known as another good alternative. ...

activerecord query as map reduce in mongodb

I would like to know how I can reproduce the following query as map reduce or any juice function from MongoMapper or MongoID: Event.find(:all,:select=>'events.company,SUM(price) as total_price', :group=> 'company',:order => ' total_price DESC, created_at DESC') ...

Querying associated collection using MongoMapper scopes?

class Comment include MongoMapper::Document scope :by_rating, lambda { |minimum| where(:rating.gte => minimum) } key :rating belongs_to :user end class User include MongoMapper::Document many :comments end User.first.comments.by_rating(3) What does the query on last line actually do? Is MongoMapper intelligent enough ...

Indices and capped collections with MongoMapper

What is the best way to set up an index or configure a capped collections in a Rails project? From what I've found, it seems that a good way would be to keep this configuration in an initializer. The command for setting up an index is ModelName.ensure_index :key, but what is the command for a capped collection? ...

How to precisely control your queries with MongoMapper

I have an index like this in my database (for my table entries): {"created_at": -1, "search_id": 1, "services":1} I can make use of that index if I perform a search in the Mongo console like this: db.entries.find({'search_id':1, 'services':2}).sort({'created_at': -1}) (if I perform an explain() on that query I can see that it's usi...

Parent association for embedded document using MongoMapper

If I have: class Post include MongoMapper::Document has_many :comments end If I do: class Comment include MongoMapper::EmbeddedDocument belongs_to :post # relevant part end Does that create an association using _root_document/_parent_document, or do I have to add the (redundant) key :post_id? ...