MongoDB and Mongoid in production
To create a production environment where you need to use a username and password to connect:
In the mongo console:
// Add an Admin User (to the admin db)
use admin
db.addUser("theadmin", "anadminpassword")
// Use your database
use supercool
// Add a user (to your database)
db.addUser("joe", "passwordForJoe")
// show all users:
db.system.users.find()
// add readonly user (kinda cool)
db.addUser("readonly", "passwordForJoe", true)
Now, all connections to your mongodb will require authentication -- http://www.mongodb.org/display/DOCS/Security+and+Authentication
Also: you can consider using your linux firewall to only allow 27017 from your web server(s).
how mongoid create index for test and production environment
As with other rake tasks for Rails, simply specify RAILS_ENV to rake on the command line,
e.g.,
rake db:mongoid:create_indexes RAILS_ENV=test
You can tail your log files in another window to watch it happen.
tail -f log/*.log
Rails - Mongoid : Slow problem between production and development
I got this!
When I saw the number of requests in production, I immediately thought of the query cache.
I found the 'identity_map_enabled' parameter for mongo, so I changed it to true, and hop magic!
Method works in development but not production Rails MongoDB
If you have a Coupon
Mongoid model then the collection in the MongoDB shell would be db.coupons
. That would explain why:
db.Coupon.insert(...)
in the MongoDB shell isn't providing what you're expecting to find in your Rails code.
As far as Neil's comment about $exists
versus explicit nil
checks goes, I think you really do want nil
(AKA null
inside MongoDB) checks. Consider this in the MongoDB shell:
> db.models.insert({ n: 11 })
> db.models.insert({ n: 0 })
> db.models.insert({ n: null })
> db.models.insert({ })
> db.models.find()
{ "_id" : ObjectId("571546e1ce2934dadf379479"), "n" : 11 }
{ "_id" : ObjectId("571546e4ce2934dadf37947a"), "n" : 0 }
{ "_id" : ObjectId("571546e7ce2934dadf37947b"), "n" : null }
{ "_id" : ObjectId("571546ecce2934dadf37947c") }
So we have a collection with documents that have n
, don't have n
, have explicit null
values for n
, and non-null
values for n
.
Then we can see the difference between Mongoid queries like :n => nil
:
> db.models.find({ n: null })
{ "_id" : ObjectId("571546e7ce2934dadf37947b"), "n" : null }
{ "_id" : ObjectId("571546ecce2934dadf37947c") }
and :n.exists => true
(AKA :n => { :$exists => true }
):
> db.models.find({ n: { $exists: true } })
{ "_id" : ObjectId("571546e1ce2934dadf379479"), "n" : 11 }
{ "_id" : ObjectId("571546e4ce2934dadf37947a"), "n" : 0 }
{ "_id" : ObjectId("571546e7ce2934dadf37947b"), "n" : null }
and :n => { :$exists => false }
:
> db.models.find({ n: { $exists: false } })
{ "_id" : ObjectId("571546ecce2934dadf37947c") }
So the :expires_at => nil
queries will find documents which don't have an expires_at
as well as documents where expires_at
was explicitly set to nil
. Both those cases will happen with Mongoid unless you're careful to call remove_attribute
instead of assigning a nil
and both cases mean "no expiry date".
Rails 5 + MongoDB issue in production
Turns out I had the mongoid.yml
config wrong, the username
and password
are supposed to be in the options
group, not outside like it was in previous versions.
Mongoid Index Creation in Production
you can build the index in the background so it won't affect your queries like this:
db.collection.createIndex( { field: 1}, {background: true} )
for more details see index build operations
Mongo vs Mongoid - why can 1 connect and the other not?
please look at: https://jira.mongodb.org/browse/RUBY-525
Should be fixed by the 1.8.2 mongo gem.
How do I deploy a rails + mongodb application to an actual domain?
Passenger, being a deployment tool, runs in the production environment by default.
Your mongoid.yml file currently only contains settings for development and test. You need to add a configuration for production.
Something like:
production:
sessions:
default:
database: myapp_production
hosts:
- localhost
Related Topics
Rails: I Can't Call a Function in a Module in /Lib - What am I Doing Wrong
How to Check What Is Queued in Activejob Using Rspec
Disable Rvm or Use Ruby Which Was Installed Without Rvm
Postgresql Gem Pg Was Unable to Install
Rails: How to Show User's "Last Seen At" Time
Sorting a Two-Dimensional Array by Second Value
Building a Windows Executable from My Ruby App
App Pushed to Heroku Still Shows Standard Index Page
Namespacing Thor Commands in a Standalone Ruby Executable
How to Structure a Layout Template in Haml
How to Dynamically Call Routes Helper in Rails
Difference Between Add_Dependency and Add_Runtime_Dependency
Ruby/Rails Using || to Determine Value, Using an Empty String Instead of a Nil Value
How to Do a Regex Search in Nokogiri for Text That Matches a Certain Beginning