mongoexport works on local but not on remote server - mongodb

When I run this code to export my local database, it works well and a file is successfully generated:
mongoexport \
--host="localhost:27017" \
-d springDb \
-c posts \
--out social.json
But when I try to access my remote server with the similar command here:
mongoexport \
--host="mongodb+srv://clustxxx.xxx.mongodb.net/xxxx" \
-d socialDeveloper \
-c posts \
--out social.json
I get this error:
error parsing command line options: error parsing URI from mongodb:///clustxxx.xxx.mongodb.net/xxxx:27017/?replicaSet=mongodb+srv:: error parsing uri: must have at least 1 host
What am I doing wrong please?

Related

No manager for connect string

As soon as my EMR-Cluster was ready to be run.
I started facing some issues when listing databases and importing sqoop
Apparently, sqoop has been installed normally and it is working normally when I type "sqoop help" in Linux terminal.
using sqoop help
as you can see, the command could be recognized normally.
However, if I try out the sqoop import command, this one cannot be and it faces an error:
sqoop import \
--connect jdbc:postgres://sportsdb.cxri########.us-east-2.rds.amazonaws.com/SportsDB \
--username postgres \
--password mypassword \
--table addresses --target-dir s3://sqoop-table-from-rds-to-s3/sqoop-table/ -m 1 --fields-terminated-by '\t' --lines-terminated-by ','
sqoop import
The same goes to the second one, which is "sqoop list-databases" as shown below:
sqoop list-databases \
--connect jdbc:postgres://sportsdb.cxri########.us-east-2.rds.amazonaws.com \
--username postgres \
--password mypassword
sqoop list-databases
they don't really works and anything happens ;/
I also downloaded jar and put into /usr/lib/sqoop/lib/ where is the jar files on sqoop
To do it I run these two follow commands:
1) wget -O postgresql-jdbc.jar https://jdbc.postgresql.org/download/postgresql-42.3.1.jar
2) sudo mv postgresql-jdbc.jar /usr/lib/sqoop/lib/
Jar file added to sqoop/lib
Someone else has a suggestion about what can be done in order to fix this issue?
The issue could be solved after following a tip received about a typo.
Then, I just changed the word postgres for postgresql as follows:
sqoop list-databases \
--connect jdbc:postgresql://sportsdb.cxri########.us-east-2.rds.amazonaws.com \
--username postgres \
--password mypassword
That is it. The issue was fixed just adjusting something pretty simple

Syntax error when running Query: "syntax error at or near "\""

I've generated a PostgreSQL script that I want to use to restore a database. When I go to my backup server to try to restore, I get the error: syntax error at or near "\".
It's getting stuck on the following characters \.
These appear like this:
COPY admin.roles (role_id, role_name, is_role_auto) from stdin;
\.
What's wrong with this statement? Is there config I missed? I'm on PostgreSQL 11.4 on Windows, the backup was taken with pg_dump, and I restore it using pgAdmin.
You cannot use pgAdmin to restore a "plain format" dump taken with pg_dump. It doesn't understand the psql syntax where COPY and its data are interleaved.
You will have to use psql to restore the dump:
psql -h server -p 5432 -U user -d database -f dumpfile.sql
It's really hard to know the specific error without seeing your backup and restore commands in their entirety, but if it helps, here is the boilerplate I use when I want to copy a table from production to a backup server:
$BIN/pg_dump -h production_server -p 5432 \
--dbname=postgres \
--superuser=postgres \
--verbose \
--format=c \
--compress=9 \
--table=admin.roles > backup.sql
$BIN/pg_restore \
--host=backup_server \
--port=5432 \
--username=postgres \
--dbname=postgres \
--clean \
--format=custom \
backup.sql
The format=c (or --format=custom) makes the content completely unreadable, but on a plus side it also avoids any weird errors with delimiters and the like, and it also perfectly copies complex data structures like arrays and BLOBs.

Return MongoDB query result to shell

I use the mongoimport command in shell to load a json file in MongoDB.
mongoimport \
--host ${MONGO_HOST}:${MONGO_PORT} \
--db ${MONGO_DB} \
--type json \
--collection ${COLLECTION} \
--file ${DATA_IN_PATH}/${FILENAME}.json \
--upsert \
--upsertFields ${UPSERT_FIELDS}
I would like to count the number of documents in my collection, before and after the load and get it in a shell variable
I tried Using the --eval command and put the result into a variable:
CollCount=$(mongo \
${MONGO_HOST}:${MONGO_PORT}/${MONGO_DB} \
--eval "db.getCollection('${COLLECTION}').count({})")
but my var CollCount contains:
MongoDB shell version: 2.6.9 connecting to: localhost:27017/mydb 12236
(The value 12236 is correct.)
Is it a better way to do this?

Why does mongoexport query with $exist fail?

I am trying to mongoexport (Version 2.6) MongoDB data into csv format using the command as follows
mongoexport --port 27017 -d test -q "{userId:{$exists:true} , name:'John'}"-c user_datas -f userId --csv -o /myOutFile.csv
and i got this error message:
assertion: 16619 code FailedToParse: FailedToParse: First character in field must be [A-Za-z$_]: offset:9 of:{userId:{true},name:John}
according to error message that something happened on '$exists' that caused the error .
whats wrong with my command?
You need to invert the quotes:
'{userId: {$exists: true} , name: "John"}'
Working command:
mongoexport \
--port 27017 \
-d test \
-q '{userId: {$exists: true} , name: "John"}' \
-c user_datas \
-f userId \
--csv \
-o /myOutFile.csv

Can't Bind for successful connection

I am trying to test a connection to AD using OpenLDAP and this is what I try on the command line:
/usr/bin/ldapsearch -h names.myorg.com \
-p 389 \
-D "cn=conapps readonly,cn=users,dc=myorg,dc=com" \
-LLL \
-x \
-b "ou=MyOrg Staff,ou=People,dc=myorg,dc=com" \
-s sub "(objectClass=*)" DN sn givenName mail userPrincipalName employeeID usertype \
-W
However, I keep getting the following error:
Operations error (1)
Additional information: 00000000: LdapErr: DSID-0C090627, comment: In order to perform this operation a successful bind must be completed on the connection., data 0, vece
Can anybody see what I am doing incorrectly?
Try port 3268 instead, see http://technet.microsoft.com/en-us/library/cc978012.aspx for more information
This command works for me:
$ ldapsearch -x -LLL -H ldap://test.com:3268 -dbc=test,dc=com -D 'DOMAIN\username' -W name=username dn
I think your password for bindDN is wrong, The bindDn which you are specifying is cn=readonly,cn=users,dc=myorg,dc=com and the password using -W is empty. It may be wrong and it is unable to authenticate you before doing a search.