mongoid3

Advice on migrating from MongoMapper to Mongoid?

岁酱吖の 提交于 2019-12-04 02:45:19
It seems like Mongoid is now the superior ORM for Mongo based on performance and development activity. Unfortunately, we're on MongoMapper and need to migrate. Are there any concerns or stumbling blocks we should be aware of? We have found a few outdated articles on Google and tried posting on the Mongoid Google Groups (though we were prohibited), but would love thoughts from SO members who have done this in the past. We're on Rails 3.2.12. Thanks! Both of them are great MongoDB Libraries for Ruby. But if you want to switch, here are some notes: Migrating MongoMapper ORM to Mongoid ORM - Notes

Connecting to two databases Mongoid

心已入冬 提交于 2019-12-03 18:53:14
问题 I have two databases that I have to use in my application. I have the following in my mongoid.yml : development: # Configure available database sessions. (required) sessions: # Defines the default session. (required) default: # Defines the name of the default database that Mongoid can connect to. # (required). database: db_development username: myusername password: mypassword # Provides the hosts the default session can connect to. Must be an array # of host:port pairs. (required) hosts: -

Unicorn triggers mongoid error during assets precompile

☆樱花仙子☆ 提交于 2019-12-03 18:01:39
问题 I have a rails app using Mongoid 3 running on Heroku. I've just updated it to use Unicorn. When I try to deploy it to Heroku I get the following error : Running: rake assets:precompile rake aborted! undefined method `match' for nil:NilClass /tmp/build_3nnbzpfmnjpns/vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.21/lib/mongoid/sessions/mongo_uri.rb:49:in `initialize' The full stacktrace can be found at http://pastebin.com/8YcJHEmS But if I remove Unicorn from my Gemfile, the assets compilation

How to programmatically get the current database Mongoid is writing to?

只谈情不闲聊 提交于 2019-12-03 11:52:15
I am talking to multiple databases using Mongoid.override_database("database_name") using Mongoid with rails. How do I find the current database programmatically? Mongoid docs on sessions: http://mongoid.org/en/moped/docs/driver.html define methods to override database but do not define a way to get the current database in use. Vamshidhar Behara Got it! Mongoid.default_session.options[:database] The new way to get this is Mongoid::Config.clients["default"]["database"] You can also just have a look at Mongoid::Config.clients to see what else is available. If you want the overrided database you

Comparability Issue rails 4 beta, ruby 2.0.0, mongoid

时光怂恿深爱的人放手 提交于 2019-12-03 08:14:35
问题 I am creating a test application using following versions of rails, ruby and mongoid. rails 4 beta ruby 2.0.0 mongoid 3.1.2 My GemFile looks like this gem 'rails', '4.0.0.beta1' ruby '2.0.0' gem 'mongoid', '~> 3.1.2' gem 'bson_ext' But when i run bundle on console I get following error. Bundler could not find compatible versions for gem "activemodel": Fetching gem metadata from https://rubygems.org/........... Fetching gem metadata from https://rubygems.org/.. Resolving dependencies...

Rails Engine + Mongoid: No configuration could be found for a session named 'default'

你。 提交于 2019-12-03 03:02:32
I've created a Rails Mountable App and added 'mongoid' and 'rspec' gem's. If I try to run my specs now I get the following error: Mongoid::Errors::NoSessionConfig: Problem: No configuration could be found for a session named 'default'. Summary: When attempting to create the new session, Mongoid could not find a session configuration for the name: 'default'. This is necessary in order to know the host, port, and options needed to connect. Resolution: Double check your mongoid.yml to make sure under the sessions key that a configuration exists for 'default'. If you have set the configuration

Comparability Issue rails 4 beta, ruby 2.0.0, mongoid

时光总嘲笑我的痴心妄想 提交于 2019-12-02 21:54:37
I am creating a test application using following versions of rails, ruby and mongoid. rails 4 beta ruby 2.0.0 mongoid 3.1.2 My GemFile looks like this gem 'rails', '4.0.0.beta1' ruby '2.0.0' gem 'mongoid', '~> 3.1.2' gem 'bson_ext' But when i run bundle on console I get following error. Bundler could not find compatible versions for gem "activemodel": Fetching gem metadata from https://rubygems.org/........... Fetching gem metadata from https://rubygems.org/.. Resolving dependencies... Bundler could not find compatible versions for gem "activemodel": In Gemfile: mongoid (~> 3.1.2) ruby depends

How to get print output for debugging map/reduce in Mongoid?

风格不统一 提交于 2019-12-01 04:41:29
I'm writing a map/reduce operation with Mongoid 3.0. I'm trying to use the print statement to debug the JS functions. This is a troubleshooting suggestion from the MongoDB docs , e.g.: reduce = %Q{ function(user_id, timestamps) { var max = 0; timestamps.forEach(function(t) { var diff = t.started_at - t.attempted_at; if (diff > max) { max = diff; } }); print(user_id + ', ' + max); return max; }; } MyCollection.all.map_reduce(map, reduce).to_a Unfortunately the output from the print statement shows up neither on the console nor on the log--it seems that this is suppressed somewhere between the

Moped::Errors::ConnectionFailure Could not connect to any secondary or primary nodes for replica set

萝らか妹 提交于 2019-11-30 06:46:56
问题 I had to forcefully shutdown my Ubuntu system after it got hanged. Now I get this error while trying to run my Rails app. Moped::Errors::ConnectionFailure (Could not connect to any secondary or primary nodes for replica set <Moped::Cluster nodes=[<Moped::Node resolved_address="127.0.0.1:27017">]>): Im using Rails 3.2.11 with Mongoid 3.1.4 . What could be wrong? 回答1: I was able to get it working by removing the mongod.lock file and restarting mongodb service sudo rm /var/lib/mongodb/mongod

Connecting to two databases Mongoid

旧时模样 提交于 2019-11-30 02:28:45
I have two databases that I have to use in my application. I have the following in my mongoid.yml : development: # Configure available database sessions. (required) sessions: # Defines the default session. (required) default: # Defines the name of the default database that Mongoid can connect to. # (required). database: db_development username: myusername password: mypassword # Provides the hosts the default session can connect to. Must be an array # of host:port pairs. (required) hosts: - myserverip:27017 databases: secondary: database: db2_development username: myusername password: