Unable to connect to remote MONGODB database __ Database

Source: Internet
Author: User
Tags auth install mongodb mongoclient mongodb mongodb client mongodb version

Install MongoDB (version 3.2.10) on the remote server (CentOS6.5), starting with the following command:

#!/bin/bash
### start MongoDB shell
### dbpath indicates the execution of the database repository (if unspecified, the default is/data/db)
### Fork means to run as daemon
### Auth indicates that an account password
is required ### "NOTE" If you specify a fork parameter, you must specify the LogPath parameter
/opt/mongodb/mongodb-3.2.10/bin/mongod--auth- Dbpath=/opt/mongodb/mongodbdata--fork--logpath=/opt/mongodb/mongodblog

Also added the user/password, and added a test library, test sets, test data;

On the server (that is, install MongoDB machine) Log on OK, query data OK;

Also confirm that the server's port is open to the public network;


But with Mongovue remote connection, anyway, the error is as follows:


Error for authentication failure, online inquiry, authentication failure, is the account or password errors;

But after confirmation, on the server login, query is no problem, it is certainly not the error.

It is also said that because the server is started, the BIND_IP parameter is missing, and if this argument is not added, the address that is allowed to access is the local address.

After the author tests, even if the parameter is added, still can not connect.


Have found a blog, said Mongovue temporarily do not support more than 3.0 of the MongoDB version,

Bowen Address: https://www.oschina.net/question/1473401_2160373

I don't understand, so the problem is still unresolved.


In addition, using the Java connection Remote MongoDB is also the same problem, unable to connect, the same error. The code is as follows:

public static void Main (string[] args) {
	list<mongocredential> credentials = new arraylist<mongocredential > ();
	Credentials.add (mongocredential.createmongocrcredential ("Zhangsan", "Demo1", "123456". ToCharArray));
	
	ServerAddress serveraddress = new ServerAddress ("localhost", 27017);
	Mongoclient mongoclient = new Mongoclient (serveraddress, credentials);
	
	Mongodatabase db = Mongoclient.getdatabase ("Demo1");
	
	Operation
	mongocollection<document> collection = db.getcollection ("person");
	Finditerable<document> it = Collection.find ();
	Mongocursor<document> iterator = It.iterator ();
	while (Iterator.hasnext ()) {
		Document doc = Iterator.next ();
		System.out.println (Doc.tojson ());
	}
	
	Close database connection
	mongoclient.close ();
}



"2016-11-04 Night 11 o'clock"

The code could not connect to the MongoDB error and finally found the reason:

Replace the Createmongocrcredential method with the Createscramsha1credential method to connect the MongoDB normally.

As for the reason, it is unknown.

Refer to Api:http://api.mongodb.com/java/current/com/mongodb/mongocredential.html

Bowen also has instructions: http://stackoverflow.com/questions/28857921/cannot-connect-to-mongodb-3-0-0-by-using-c-sharp-driver-1-10


Through another MONGODB client Robomongo0.9.0 connection interface, and then guess Mongovue can not connect MongoDB, it is also estimated because the mongovue of the underlying method has not been modified. Screenshot below:





Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.