Disable MongoDB from rails 3.0.9 application start up? - ruby-on-rails

My project uses both MySQL(for ActiveAdmin tables) and MongoDB(for rake task that does logs file parsing) as database. I have used Mongoid to connect my app to MongoDB. So I just have mongoid.yml file extra in /config directory along with other usual files(No other files to setup MongoDB connection). However whenever I try to run migrations for MySQL or start my app it requires MongoDB running in the background else the server/task wont start and gives an error
Failed to connect to a master node at localhost:27017 (Mongo::ConnectionFailure)
Keeping MongoDB continuously running is not required. Please guide me in excluding this compulsion.

There seems to be some discussion on this topic here: https://github.com/mongoid/mongoid/issues/1166
Perhaps you could wrap the connection so that it checks for a certain flag or environment variable which you would use for mysql only mode.

Related

Ruby On Rails - "OpenSSL::Cipher::CipherError at ..." when connecting to imported database

I am running my Ruby On Rails 5 app on localhost and now, I imported the production database. It's a PostgreSQL database, exported via the pg_dump tool.
When I modified the database.yml file the Rails app and set there the newly created database, I got this error when running the Rails app (tried also to change the port on which the app is running, but it didn't help):
OpenSSL::Cipher::CipherError at /
In the Rails console is not any information about the error.
What is the reason of such an error? I tried to export the database from the staging server and use it on localhost and everything worked fine.
Based on the docs: https://ruby-doc.org/stdlib-2.4.1/libdoc/openssl/rdoc/OpenSSL/Cipher.html#method-i-final
It looks like you don't have the proper encryption key to connect to the production db.
I would guess you either do have the proper one for staging, or staging is running unencrypted.
Here's someone else with the same error caused by an incorrect key: OpenSSL::Cipher::CipherError when running staging DB on local

Error while typing rails server command

I am a beginner.I am trying to launch rails server using the command.But I am getting an error. I tried searching in the google but no results.I will attach a picture of the log I got when I executed that command.
What Mysql error are you getting?
And what is in your config/database.yml?
So far, you have created the folder structure for a Rails app (rails new), then installed all the relevant components (bundle install).
When you start the server (rails server) it starts in "development" mode (you also have "test" mode for unit tests and "production" mode for when your app is live - and each has slightly different options). One of the first things the Rails server tries to do is connect to the database, so it looks in config/database.yml for the database specified in the development section.
So probably, it's trying to connect to a database that doesn't exist yet, with a username and password that are wrong.
First thing to do is to update the username and password in config/database.yml to match your local Mysql server.
Second thing to do is to build the development database; the command for that is "bin/rake db:create" (or "bundle exec rake db:create" if you're on Rails 3.x).
Hopefully that should be enough to get your server started.
How did you setup your rails app?
It seems like maybe you didn't type
bundle install
This command downloads and updates all of your gems. Action View is a rails dependency.

Postgres failed to create database for rails-composer

I'm running the rails-composer script with
rails new myproject -m https://raw.github.com/RailsApps/rails-composer/master/compser.rb
And everything goes along smoothly until it asks me if I want to go ahead and drop the db in. I say yes. All drops fail, and all creations fail.
Everything else finished fine. And testing the site brings up a beautiful error site with lots of details on how the database password wasn't accepted. But of course it was never created...
How do I give the script permission to create the database without a password? I've tried preempting creating the username as the app name in postgres. I tried building the Rails project as the postgres user.
It should be a simple and straightforward solution since the rest is automated.
Did you specify something other than SQLite for the database?
From the README:
Choose “SQLite” for the easiest setup. If you choose PostgreSQL or
MySQL, the databases must be installed and running before you run
Rails Composer.
Rails composer does not install and setup your database server for you. It assumes there's a properly named database already present before you run this if you're using PostgreSQL or MySQL.

Two Terminal sessions with different results

I'm setting up a new computer to use an existing Rails application (Rails 3.2 with Postgres). I installed postgres via homebrew, along with the Lunchy gem as documented here: http://www.moncefbelyamani.com/how-to-install-postgresql-on-a-mac-with-homebrew-and-lunchy/. No problems getting a user account and starting/running my application. I ran rake db:create:all to create all of the databases. The site works and loads from only one Terminal tab.
When I open a new tab, same location, and try to start the server, I get the following error:
Users/jpetrarca/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-3.2.13/lib/active_record/connection_adapters/postgresql_adapter.rb:1216:in `initialize': could not connect to server: No such file or directory (PG::Error)
19:24:39 web.1 | Is the server running locally and accepting
19:24:39 web.1 | connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?
I don't know why one terminal session would work and another not.
Interestingly, I can start/stop postgres with lunchy from the non-working terminal and it does, in fact, use the same service and turns off the db being accessed from the working terminal (which is expected).
I initially found this problem while trying to run my rspec tests and connect to the test db.

Can't connect dumped MongoDB with Rails 3.1 and Mongoid

A Rails 3.1 app is running locally fine with MongoDB and mongoid (until I don't modify anything).
I need the production DB so I dumped it properly. Now I need to configure the Rails app to connect or use this new dumped database.
I copied all the Mongodb's BSON files into the folder where my local Mongo (which started by 'mongod' command) looking for (/data). All files in one folder (/data/e).
How to configure MongoDB or Rails or mongoid.yml to use specifically that folder which I moved there?
+++
Additional info:
Made mongodump successfully. Now I need to import it to the testserver, probably with mongoimport. How to do that?
You don't do that. To dump/restore a MongoDB database, you should use the mongodump and mongorestore utilities

Resources