MongoDB Charts Error while testing connection - mongodb

I am trying to deploy mongo charts on containers. While testing i get below error
I tried serching web .. but did not get right fix
docker run --rm quay.io/mongodb/charts:19.06.1 charts-cli test-connection mongodb://unsername:password#mon009.abc.com:7041,mon001.abc.com:7041/pub_mongo?replicaSet=mongo7041
i get below error .. any clue??
Unable to connect to MongoDB using the specified URI.
The following error was returned while attempting to connect:
MongoParseError: Incomplete key value pair for option

I can't repro the problem with the supplied URI. The only thing I can think of is that the redacted password may contain a special character such as ? which is preventing the URI from being parsed. Make sure you are URL-encoding any special characters in the password.

Related

Mongodump fails with "a direct connection cant be made if multiple hosts are specified"

I have a dev & staging database which i connect to regularly (using mongoose.connect(<uri>)).
I would like to mongodump them. Im using the following syntax:
mongodump --uri=<uri>
This works fine for dev and I was able to dump the dev database using this command. The staging database however produces the following error:
Failed: can't create session: error configuring the connector: a direct connection cannot be made if multiple hosts are specified
Does anyone know or have any insight on what the issue could be? I haven't found any docs or posts about this error.
Historically, when given a URI with one host in it (or otherwise a single host to connect to), some MongoDB drivers performed a direct connection to that host only and some drivers inspected the type of the server and, if it was a replica set node, connected to replica set (which may have caused none of the queries or commands to be sent to the host which was originally given in the URI).
In the MongoDB 4.4-compatible drivers the behavior was unified, and directConnection URI option added to force either behavior (true to connect to the specified host, false to perform discovery; if not set, the driver would do whatever it did historically).
When direct connection is used, you can only specify one host. Your URI contains or resolves to more than one.
For the gritty details, see https://github.com/mongodb/specifications/pull/739.

When using MongoStat, how do you correctly format the connection string?

I am trying to use MongoStat to monitor my database deployment. Below is the command I'm using to try and connect:
mongostat --uri "mongodb+srv://user:password#subdomain.azure.mongodb.net/admin?replicaSet=project-shard-0&connectTimeoutMS=10000&authSource=admin&authMechanism=SCRAM-SHA-1"
This produces the error:
error configuring the connector: error parsing options from URI: error parsing uri: URI with srv must not include a port number
The connection string format that I'm using does actually work when used with MongoRestore. But with MongoStat, I get this error. Does anyone here know how I can properly format this connection string?
man mongostat shows this:
--uri=<connectionString>
New in version 3.4.6.
Specify a resolvable URI connection string (enclose in quotes) to connect to the MongoDB deployment.
--uri="mongodb://[username:password#]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database][?options]]"
Stands to reason that if you try this command instead, it should work:
mongostat --uri="mongodb+srv://user:password#subdomain.azure.mongodb.net/admin?replicaSet=project-shard-0&connectTimeoutMS=10000&authSource=admin&authMechanism=SCRAM-SHA-1"

Setting db in Studio3T intellishell

I am trying to execute a query in IntelliShell, However when I open intellishell for a particular collection and execute a simple find query I get the following error:
Failed to retrieve documents
[null.WidgetPublished#STAGE_QA sjc-wwdl-pmp2:27017 [direct]] : An error occurred while retrieving documents!
Stacktrace:
|_/ java.lang.Exception: [null.WidgetPublished#STAGE_QA sjc-wwdl-pmp2:27017 [direct]] : An error occurred while retrieving documents!
|____/ Illegal argument: Database must be set.
Now, I know that this is happening because there is no db set up for my mongo host. However I am unable to set the db. I'm using the following command to set it, but nothing seems to work.
use dgmdetails; where dgmdetails is my db name.
So I was able to resolve it. in my mongo.conf file on the server. I needed to disable some authorization that was enabled which was not letting the user that I was logging in with, to connect to the db.
I'm pretty sure this was an issue faced just by me due to the configuration. However, there is a possibility that someone else might find this useful too.

cannot connect to azure postresql - Username should be in <username#hostname> format

I'm trying to use azure PostgreSQL for CKAN (ckan.org)
CKAN is using http://www.sqlalchemy.org/ for database connection.
A connection string looks like this:
engine = create_engine('postgresql://scott:tiger#myhost.postgres.database.azure.com:5432/mydatabase')
syntax is:
postgresql://username:password#hostname:5432/databasename
When trying to connect to azure postgresql I get this error:
FATAL: Invalid Username specified. Please check the Username and
retry connection. The Username should be in username#hostname format.
If I try to use the username format like this:
postgresql://scott#myhost:tiger#myhost.postgres.database.azure.com:5432/mydatabase
Then I get:
invalid port number: "tiger#myhost.postgres.database.azure.com:5432"
Has anyone solved this?
The invalid port number is caused by the # in the user name.
The connection url should look like this:
postgresql://scott%40myhost:tiger#myhost.postgres.database.azure.com:5432/mydatabase
Extending Allan Kristensen's answer, you'll end up with problem if you're using the datastore extension (Bundled with CKAN Core).
Looking at the codebase of CKAN the problem is in https://github.com/ckan/ckan/blob/555e0960c43d0ca86066b1954e5c94aad565baa7/ckanext/datastore/backend/postgres.py#L1592 (or https://github.com/ckan/ckan/blob/ckan-2.6.4/ckanext/datastore/plugin.py#L200 if you're running 2.6.5 or less)
Thus, when CKAN queries the database with SELECT has_table_privilege('scott#myhost', '_foo', 'INSERT') it's fail, as there's no user named scott#myhost. Azure is doing something funky with the usernames, as if you ask the database to list the users, you'll see that the database thinks your username is scott (Atleast that's what it did for me...)
One possible, hackish, fix is:
sed -i '' 's/read_connection_user = sa_url.make_url(self.read_url).username/read_connection_user = split(sa_url.make_url(self.read_url).username, "#")[0]/' /srv/app/src/ckan/ckanext/datastore/plugin.py
sed -i '' 's/import sys/import sys\nfrom string import split/' /srv/app/src/ckan/ckanext/datastore/plugin.py
The above works for 2.6.5. Substitute the file path with /srv/app/src/ckanext/datastore/backend/postgres.py if you're running 2.7+
The above should work until upstream have found a proper fix.

'No reachable servers' error when beginning parse migration with MongoDB

I am in the process of migrating my app from Parse to MongoDB and IBM Bluemix, however I can't seem to reach the server when attempting the migration of data from Parse.
I've been following this tutorial tutorial, and I am currently on the step: Migrating data from Parse.com to your MongoDB instance
I am currently getting this error: No reachable servers when clicking 'Begin the migration'.
These are the connection strings in compose:
And I have tried entering various strings. I assumed this would work:
mongodb://username:password#aws-us-east-1-portal.7.dblayer.com:10803/mtcdatabase
But I get the same error. Obviously I'm changing username and password to my own credentials.
Anyone have any suggestions?
The issue ended up being that I was using the latest version of MongoDB, however Parse doesn't seem to support it. Therefore, I had to use MongoDB Classic version 3.0. Everything works great now.