Reputation: 191
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:[email protected]:42487/db-name
Any suggestions on how to fix this??
Thanks
Upvotes: 7
Views: 13278
Reputation: 1
I just solved this problem. In the .env file:
MONGO_URL = mongodb+srv://papi:****@cluster0.zvhnr7t.mongodb.net/social media app?retryWrites=true&w=majority
I fixed it by removing the space between social media app like this:
MONGO_URL=mongodb+srv://papi:*****@cluster0.zvhnr7t.mongodb.net/socialmediaapp?retryWrites=true&w=majority
so remove the space and check also there is no space between the username and password.
Upvotes: 0
Reputation: 191
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. :)
Upvotes: 11
Reputation: 754
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
Upvotes: 0
Reputation: 38952
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.
Upvotes: 3