MongoDB password with “@” in it

前端 未结 16 1791
遇见更好的自我
遇见更好的自我 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:30

    use pwd instead pass, that worked for me for version3.2

    mongoose.connect('mongodb://localhost/test',
                     {user: 'username', pwd: 'p@ssword'},
                     callback);
    
    0 讨论(0)
  • 2020-11-27 14:34

    Use this syntax:

    mongoClient.connect("mongodb://username:p%40ssword@host:port/dbname?authSource=admin", { 
            useNewUrlParser: true
        }, function(err, db) {
    
        }
    );
    
    0 讨论(0)
  • 2020-11-27 14:34

    This one worked for me

    This one is a MongoDB 2020 Update If You're using a separate env file then just add your

    mongoose.connect('url',
    {
        useNewUrlParser: true, 
        useUnifiedTopology: true 
    });
    
    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题