M
M
mortify2016-05-01 18:20:23
ruby
mortify, 2016-05-01 18:20:23

How to connect Mongoid?

There is ruby, so far without any frameworks.

require 'mongoid'

Mongoid.load!("mongoid.yml", :development)

class Test
  include Mongoid::Document
  field :name, type: String
end

mongoid.yml file
development:
  clients:
    default:
      database: mydatabase
      hosts:
        - localhost:27017

Next, what do we have. When we create instances of the class through create or write a .save method and back it up with outputs of success messages to the console - we see that everything is wonderful, in the mongod console we also see messages of this kind after executing the script
2016-05-01T18:18:23.793+0300 I NETWORK  [conn4] end connection 127.0.0.1:38957 (2 connections now open)

however, if you write in the console
mongo
use mydatabase
db.mydatabase.find()

the answer is emptiness. Maybe I don't understand how mongoid works at all, but damn it :/ please help

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question