You can confirm that you can create the database, add a collection to the database and add documents to the collection directly from IRB:
$ rvm use 2.4.1
$ rvm-prompt
$ ruby-2.4.1
$ rvm gemset create mongoid_test
$ rvm use @mongoid_test
$ gem install mongoid
$ gem list | grep mongoid
$ mongoid (7.0.2)
$ rvm-prompt
$ ruby-2.4.1@mongoid_test
$ irb
> require 'mongoid'
=> true
> Mongoid.load!('mongoid.yml', :development)
=> {"clients"=>{"default"=>{"database"=>"mongoid_test", "hosts"=>["localhost:27017"]}}}
> class LineItem
include Mongoid::Document
include Mongoid::Attributes::Dynamic
end
> item = LineItem.new
> item['cost'] = 12.00
> item['quantity'] = 3
> item['name'] = 'Protein Bars'
> item.save!
=> true
> LineItem.all.size
=> 1
> i = LineItem.first
=> #<LineItem _id: 5c552b8d496a9d0828b374b5, cost: 12.0, quantity: 3, name: "Protein Bars">
> i.fields.keys
=> ["_id"]
i.inspect_dynamic_fields
=> ["cost: 12.0", "quantity: 3", "name: \"Protein Bars\""]
Open up the MongoDB shell and confirm your data is there:
$ mongo
> show dbs
admin
config
local
mongoid_test
> use mongoid_test
switched to db mongoid_test
> show collections
line_items
> db.line_items.find({ cost: 12.0, quantity: 3, name: 'Protein Bars'}, {_id: 0})
{ "cost" : 12, "quantity" : 3, "name" : "Protein Bars" }
Straight forward, flexible and, well, quite dynamic.