2

Simplified case:

I create a new rails 3.2 project, without active record. I add mongoid 3.0.0.rc to the Gemfile and then rails g mongoid:config. I edit my mongoid.yml to look like the one I have posted below (except that hosts is now set to localhost:27068).

I have added an admin user to mongodb:

$ mongo localhost/admin
> db.addUser(myadmin,adminpass)

Also I have added a regular user to my database:

use mydb
> db.addUser(myuser, mypassword)

I confirm that I can connect to my database:

$ mongo localhost/mydb -u myuser -pmypassword
MongoDB shell version: 2.0.4
connecting to: localhost/mydb
> _

After that, I start mongod with --auth switch to force authentication:

$ mongod --auth --dbpath /my/db/path

Now that everything seems to be OK, I create some random scaffold like:

$ rails g scaffold User name email

and try to run the project in the browser: localhost:3000/users. BOOM! I'm hit with the error message posted below.

Is this a bug in mongoid? Or am I missing something?


Original Question

I'm unable to do anything on my MongoHQ hosted database in a Rails 3.2 project with mongoid 3 rc. A simple query for login action gives me something like this error message:

The operation: #<Moped::Protocol::Query
  @length=83
  @request_id=3
  @response_to=0
  @op_code=2004
  @flags=[]
  @full_collection_name="mydb.users"
  @skip=0
  @limit=-1
  @selector={"name"=>"Abbas"}
  @fields=nil>
failed with error 10057: "unauthorized db:mydb lock type:-1 client [some ip]"

Here's what my mongoid.yml looks like:

development:
  sessions:
    default:
      database: mydb
      user: myuser
      password: mypassword
      hosts:
        - flame.mongohq.com:27068
      options:
        consistency: :strong
  options:
    include_type_for_serialization: true

So I'm doing it the wrong way. The db user is not marked as "Read-only" in MongoHQ panel. And I'm NOT deploying to Heroku; just testing on my localhost.

Any help is appreciated.

Abbas Mashayekh
  • 301
  • 3
  • 12

0 Answers0