Skip to content
This repository has been archived by the owner on Jan 15, 2024. It is now read-only.

Connecting with a URI causes error #10

Closed
paulelliott opened this issue May 30, 2012 · 15 comments · Fixed by mongodb/mongoid#2057
Closed

Connecting with a URI causes error #10

paulelliott opened this issue May 30, 2012 · 15 comments · Fixed by mongodb/mongoid#2057
Milestone

Comments

@paulelliott
Copy link

When I set up my configuration with a URI, like for MongoHQ on Heroku, I get the following error:

The operation: # Moped::Protocol::Query
@Length=144
@request_id=5
@response_to=0
@op_code=2004
@flags=[:slave_ok]
@full_collection_name="..."
@Skip=0
@limit=0
@selector={"$query"=>{...}}
@fields=nil>
failed with error 13075: "db name can't be empty"

@durran
Copy link
Member

durran commented May 30, 2012

Paul can you show the full uri in your config please?

@paulelliott
Copy link
Author

mongodb://heroku:@subdomain.mongohq.com:99999/database-name

@paulelliott
Copy link
Author

We did not change the URI environment variable value at all when we upgraded from mongoid 2. Everything was working fine under the previous version.

@durran
Copy link
Member

durran commented May 31, 2012

Oh wait, I just realized you put this in the Moped repo... Are you trying to instantiate a Moped session with a URI? That is not allowed... Mongoid support's it in the mongoid.yml, but Moped's API take an array of host/port strings to it's constructor:

http://rdoc.info/github/mongoid/moped/Moped/Session

@paulelliott
Copy link
Author

No, I am connecting through mongoid and the uri setting is in our mongoid.yml. I put it in here because the error referred to moped.

@durran
Copy link
Member

durran commented May 31, 2012

Can you also show me the mongoid.yml please?

@paulelliott
Copy link
Author

settings: &settings
  allow_dynamic_fields: true
  identity_map_enabled: false

development:
  sessions:
    default:
      <<: *settings
      hosts:
        - localhost:27017
      database: development

test:
  sessions:
    default:
      <<: *settings
      allow_dynamic_fields: false
      hosts:
        - localhost:27017
      database: test<%=ENV['TEST_ENV_NUMBER']%>

sandbox:
  sessions:
    default:
      <<: *settings
      uri: <%= ENV['MONGOHQ_URL'] %>

staging:
  sessions:
    default:
      <<: *settings
      uri: <%= ENV['MONGOHQ_URL'] %>

production:
  sessions:
    default:
      <<: *settings
      uri: <%= ENV['MONGOHQ_URL'] %>

@durran
Copy link
Member

durran commented Jun 1, 2012

First, change this:

options: &settings
  allow_dynamic_fields: true
  identity_map_enabled: false

Then they are being extended in the wrong place... Should be:

development:
  <<: *settings
  sessions:
    default:
      hosts:
        - localhost:27017
      database: development

@durran
Copy link
Member

durran commented Jun 1, 2012

And is your URI really malformed like the one you posted (ie the heroku: part)? Should be:

"mongodb://user:pass@host:port,host:port/database-name

@durran
Copy link
Member

durran commented Jun 1, 2012

I've got specs all around this, just added more for when the URI is the default session and not the secondary.

mongoid/mongoid@fb2cae2

With the malformed URL I get a different error - just want confirmation that's what you've got but since my error is different I may need more information to reproduce.

@paulelliott
Copy link
Author

No, it isn't malformed. When I de-identified it I replaced the password with <password> and it got stripped out.

I moved the settings extend to the correct place and it had no affect. It looks like the URI parsing is ignoring the database name at the end. I tried to explicitly set it in the mongoid.yml and got this error:

Both uri and standard configuration options defined for session: 'default'.

@durran
Copy link
Member

durran commented Jun 1, 2012

Are there any special characters in your database name maybe? Here's the class that is parsing it - I'm wondering if we have a regex problem...

https://github.com/mongoid/mongoid/blob/master/lib/mongoid/sessions/mongo_uri.rb

@paulelliott
Copy link
Author

There is a hyphen in it but that isn't breaking your regex. I just added a spec to test that specifically and it looks fine.

-- Paul

On Friday, June 1, 2012 at 9:16 AM, Durran Jordan wrote:

Are there any special characters in your database name maybe? Here's the class that is parsing it - I'm wondering if we have a regex problem...

https://github.com/mongoid/mongoid/blob/master/lib/mongoid/sessions/mongo_uri.rb


Reply to this email directly or view it on GitHub:
#10 (comment)

@hanshasselberg
Copy link
Contributor

Ok, I can reproduce your problem.

@hanshasselberg
Copy link
Contributor

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants