6

I am trying to insert document using mongoengine in my python script but it raises this exception

(<class 'pymongo.errors.InvalidName'>, InvalidName("database names cannot contain the character '.'",), <traceback object at 0x000000000844F708>)

Connection string is mongodb://user:pass@ds042487-a0.mlab.com:42487/db-name

Any suggestions on how to fix this??

Thanks

O. Jones
  • 103,626
  • 17
  • 118
  • 172
Mustafa Khalid
  • 161
  • 1
  • 1
  • 8

3 Answers3

9

Rather than using

connect("mongodb://user:pass@server_url:port/db-name")

use this

connect( db='db-name', username='user', password='pass', host='mongodb://user:pass@server_url:port/db-name')

It worked for me. :)

Mustafa Khalid
  • 161
  • 1
  • 1
  • 8
2

Your database name shouldn't contain any of these characters: ' ', '.', '$', '/', '\\', '\x00', '"'

Check your database name. The Mongo driver also enforces this rule so the chance that you have a database with a dot in its name is slim.

Oluwafemi Sule
  • 36,144
  • 1
  • 56
  • 81
0

I use python driver 3.4v which is shared cluster format connection string, I try diferent connection string but it doesn't work for me, here's the Connection Strings URI Format for mongoengine

Marvin
  • 647
  • 7
  • 15