Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mongo::InvalidNSName - database names cannot contain the character '.': #7

Conversation

fairchild
Copy link

I was getting the error in the title, so changed the database names to use - instead of .

Here is the relevant section from the mongo driver:

# File 'lib/mongo/util/support.rb', line 48

def validate_db_name(db_name)
  unless [String, Symbol].include?(db_name.class)
    raise TypeError, "db_name must be a string or symbol"
  end

  [" ", ".", "$", "/", "\\"].each do |invalid_char|
    if db_name.include? invalid_char
      raise Mongo::InvalidNSName, "database names cannot contain the character '#{invalid_char}'"
    end
  end
  raise Mongo::InvalidNSName, "database name cannot be the empty string" if db_name.empty?
  db_name
end

for example, oauth2-clients instead of oauth2.clients.
Some versions of Mongo did not like dots in the name
@assaf
Copy link
Contributor

assaf commented Mar 15, 2011

From the MongoDB specification:

Collections can be organized in namespaces; these are named groups of collections defined using a dot notation. For example, you could define collections blog.posts and blog.authors, both reside under "blog".

@assaf assaf closed this Apr 11, 2011
@assaf
Copy link
Contributor

assaf commented Jul 14, 2011

To elaborate:

Database names cannot contain dots

Collection names can contain dots

This pull request was to remove dots from collections, although the exception has nothing to do with collections, and collections do allow dots.

If you see this error in your code, chances are you set Server.database to a MongoDB connection instead of a database object.

assaf added a commit that referenced this pull request Jul 14, 2011
@fairchild
Copy link
Author

Yep, yer right. thanks

@zambon
Copy link

zambon commented Sep 19, 2012

How about this, any clues? I made sure I'm using a connection object, not a database one.

> Rack::OAuth2::Server.get_issuer 'www.facebook.com'
Mongo::InvalidNSName: collection names must not start or end with '.'

If it helps:

mongoid (2.4.12)
rack-oauth2-server (2.8.0)

@zambon
Copy link

zambon commented Sep 21, 2012

Forcing oauth.collection_prefix = 'oauth2' did the trick.

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

Successfully merging this pull request may close these issues.

None yet

3 participants