MongoDB password with “@” in it

前端 未结 16 1950
遇见更好的自我
遇见更好的自我 2020-11-27 14:03

I\'m trying to connect to a MongoDB database with a username and password using Mongoose in Node.js. All the docs say that the connection string should look like

<         


        
16条回答
  •  时光取名叫无心
    2020-11-27 14:36

    I was attempting this in python and I had a similar error. This worked for me.

    import pymongo
    
    client = pymongo.MongoClient("mongodb://username:12%40password@ip:27017/sample_db") 
    db = client.sample_db
    # print the number of documents in a collection
    print(db.collection.count())
    

    12%40password represents your password and assumes it has a special character (e.g. @ - represented by %40) - username is your mongodb username , ip - your ip address and sample_db the database under mongodb that you wish to connect to.

提交回复
热议问题