To use MongoDB with Ruby on Rails, you will need to install MongoDB on your system and the MongoDB Ruby driver. Then, you will need to set up your Rails application to work with MongoDB.
Here is a step by step guide:
1. Install MongoDB on your system: You can find the official installation guide at https://docs.mongodb.com/manual/installation/
1. Install MongoDB Ruby driver: To interact with MongoDB through a Ruby application, you need a MongoDB driver. The official MongoDB driver for Ruby should be added to your Gemfile:
\`\`\` gem ‘mongo‘ \`\`\` Then run `bundle install` command.1. Install Mongoid: Mongoid is the officially supported MongoDB ODM (Object-Document-Mapper) for Ruby on Rails. To install, add the following to your Gemfile:
\`\`\` gem ‘mongoid’, ‘~> 7.0.5‘ \`\`\` Then run `bundle install` to install the gem.1. Generate Mongoid configuration: Run `rails g mongoid:config`. This will create the `config/mongoid.yml` file which contains Mongoid’s settings.
1. Set up the Rails model to work with MongoDB: Instead of inheriting from `ActiveRecord::Base`, Rails models using MongoDB should inherit from `Mongoid::Document`.
Here is a basic example of a model:
```
class Person
include Mongoid::Document
field :first_name, type: String
field :last_name, type: String
end
```
1. Working with Data: The Mongoid ODM provides a simple and intuitive API for creating, retrieving, updating and deleting data:
```
That’s it, you can now use MongoDB with Ruby on Rails.
Note: Before starting rails server make sure that mongoDB server is running. Use `sudo service mongod start` to start MongoDB server.