Search code examples
pythonmongodbpymongomlab

MongoEngine: database names cannot contain the character '.'


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


Solution

  • 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. :)