I'm trying to learn how to use MongoDB with C# applications. I installed MongoDB on a CentOS 7 VM (VMWare) but I cannot seem to get a connection.
I've set up my database following the example shown here:
MongoDB: Server has startup warnings ''Access control is not enabled for the database''
Except I later changed the role to "root" because mongod gave me some warnings I tried to fix.
Here's what my Main function looks like:
static void Main(string[] args)
{
string connectionString = "mongodb://myUserAdmin:abc123@192.168.27.129:27017";
var client = new MongoClient(connectionString);
var database = client.GetDatabase("test");
bool isMongoLive = database.RunCommandAsync((Command<BsonDocument>)"{ping:1}").Wait(1000);
if (isMongoLive)
{
Console.WriteLine("Connected!");
}
else
{
Console.WriteLine("No connection!");
}
Console.ReadLine();
}
All I ever get is the "No connection!" output, which makes me think there might be something wrong with my connection string. But I've created the myUserAdmin user in the admin database with the abc123 password like in the example above, and the ifconfig command on my CentOS VM returns 192.168.27.129. And as in the above example as well, I started the daemon with port 27017.
I attempted to add an entry into the DB and it just takes a long time and eventually times out.
I don't know what I'm missing, any help is greatly appreciated!
Update: I've now installed MongoDB on my local Windows PC and set up the DB the same way, also launched the daemon with --auth. Oddly I was able to connect with both, a connection string containing the credentials and the standard one without them. Anyway it seems to work locally but not on the VM.
Update 2: I tried commenting out the bindIp line in /etc/mongod.conf as well as replacing it with bindIp: 0.0.0.0,::. I also attempted to log in via Putty and see if that works, and it did without the credentials. So I deleted them from my connection string as well but the program still cannot establish a connection. It did not work with the credentials because somehow the myUserAdmin user disappeared. But I launched the daemon again without --auth because the issue doesn't seem to lie with the authentication anyway.