Getting unauthorized error during bulk insertions - mongodb

I am dumping some collections and trying to restore them to cosmosDb
Dumping method
mongodump --host localhost:5960 --db test --collection ‘collectionName’ --gzip --out /mongoBackupFolder/
Restoring method
mongorestore --host blahblah.azure.com --port 9999 -u user -p password --db dummyData --collection dummyData /mongoBackupDB/dummyData/dummyData.bson.gz --gzip --ssl --sslAllowInvalidCertificates
In some collections I have milions of data and sometimes during insertion time i am getting
Error 13 : Insert Error
Error 13 is 13 Unauthorized The request lacks the permissions to complete. Ensure you are using the correct keys.
The error in azure portal
The portal is having issues getting an authentication token. The experience rendered may be degraded.

Related

authenticationDatabase error when running mongoimport

when doing the m103 mongodb course i came across this error when doing the import lab:
user#NHTTPR# mongoimport /dataset/products.json -h localhost:27000 -u m103-application-user -p “m103-application-pass” --authenticationDatabase admin --db applicationData --drop --collection products
2021-04-07T06:19:23.616+0000 error connecting to host: could not connect to server: connection() : auth error: sasl conversation error: unable to authenticate using mechanism "SCRAM-SHA-256": (AuthenticationFailed) Authentication failed.
the solution was to put single quotes (') around the password. instead of double quotes ( or remove the quotes around the password entirely)
mongoimport /dataset/products.json -h localhost:27000 -u m103-application-user -p 'm103-application-pass' --authenticationDatabase admin --db applicationData --drop --collection products
2021-04-07T06:20:25.025+0000 connected to: mongodb://localhost:27000/
2021-04-07T06:20:25.026+0000 dropping: applicationData.products
2021-04-07T06:20:25.423+0000 9966 document(s) imported successfully. 0 document(s) failed to import.
user#NHTTPR#
use single quote or dont use any quotes following works
mongoimport --username m103-application-user --password m103-application-pass --port=27000 --authenticationDatabase admin --db applicationData --drop --collection products /dataset/products.json

Mongorestore from localhost to cosmosDb fails with "disable retryable writes by specifying "retrywrites=false"

mongo client v 4.4
mongorestore --host <host> --port 10255 -u <user> -p <password> --db <db_name> --collection structures structures.bson --ssl --sslAllowInvalidCertificates
2020-10-03T23:13:44.440+0300 Failed: <db_name>.structures: error restoring from structures.bson: (BadValue) Retryable writes are not supported. Please disable retryable writes by specifying "retrywrites=false" in the connection string or an equivalent driver specific config.
I tried the other way
mongorestore "mongodb://<host>:<password>#<name>:10255/?ssl=true&retrywrites=false&appName=#name#" dump/
with the same error.
I found that this command --writeConcern="{w:0}" can solve the "rewrite=false" error. I have tried it and here's my command.
mongorestore.exe --uri "<cosmosdb_connect_string>" --db Database1 --collection collection1 --ssl --sslAllowInvalidCertificates edx-dump/Database1/collection1.bson --writeConcern {w:0}

Error while importing JSON data from mongo shell to my Atlus cluster

I need to import data from a JSON file to a cluster in Atlas mongodb.
I looked into the documentation and found the following command
mongoimport --host centarosa-shard-0/centarosa-shard-00-00-eplsl.mongodb.net:27017,centarosa-shard-00-01-eplsl.mongodb.net:27017,centarosa-shard-00-02-eplsl.mongodb.net:27017 --ssl --username parvarish --password --authenticationDatabase admin --db --collection --type --file
The error that I am getting is :
Failed: error connecting to db server: no reachable servers
I also tried updating my mongodb version to 4.0.1
But still getting the same error
Please guide me through this.
Thanks
The code provided is missing required arguments. Try the code below, replacing the bolded values with those appropriate for your environment.
mongoimport --host centarosa-shard-0/centarosa-shard-00-00-eplsl.mongodb.net:27017,centarosa-shard-00-01-eplsl.mongodb.net:27017,centarosa-shard-00-02-eplsl.mongodb.net:27017 --ssl --username parvarish --password MYPWD --authenticationDatabase admin --db MYDB --collection MYCOLLECTION --type json --file C:\PATH\IMPORT-FILE.json --jsonArray

How to restore user defined javascript functions in MongoDB?

I restored MongoDB production database to our testing environment using the mongodump and mongorestore commands. There were 414 user defined functions in our database and none of them were restored. How can I restore the functions in the production environment in the testing environment?
It is pretty simple. The system.js function is also a collection. So you can dump the collection using the following command and restore using the mongorestore command.
mongodump --host youripaddressorlocal --port yourportnumber --username "username" --password "password" --authenticationDatabase admin --collection system.js --db databasename
mongorestore --host localhost --port 27017 --username "username" --password "yourpassword" --collection system.js --drop --db yourdatabase dump/baabtra_db/system.js.bson
--drop is used so that if the function is already there, it will be deleted. Incase if you are still getting the error and if you are not able to delete it, you can use the following command to delete all the functions in the mongoDb.
db.system.js.remove({})
Please note that the curly braces are very important.

MongoDB - dump and restore across different host, db with oplog

Is it possible to take a mongodump and mongorestore it to a different hosts, with different DB names, with oplog enabled?
From: mongodb://user:password#source-hostname:source-port/db1
To: mongodb://user:password#dest-hostname:dest-port/db5
When I do a mongodump with oplog on the source MongoDB, it takes a dump of the entire DB.
mongodump --oplog --host <source-hostname> -u <user> -p <password> --port <source-port> --authenticationDatabase admin
Now for the restore, I want to restore to a different hostname, and the db-name is also different. Is there way to restore the data to this db, with the oplogReplay?
mongorestore --host <dest-host> --port <dest-port> --username <user> --password <password> --authenticationDatabase admin --oplogReplay --db <db5> <path-to-dump>/dump
If I use oplogReplay, I am getting the following error
Can only replay oplog on full restore
I do not want to do a full restore, as it will create the db-name as db1, whereas I want to make use of db5. Also, there are already multiple DBs on this destination host and I do not want to bombard with another new database.
Any suggestions on this issue?
You can't use two options --oplogReplay and --db at the same time.
If you don't want to restore the full DB, simply go to dump/ folder and delete files for DBs other than db5. Then retry mongorestore without --db:
mongorestore --host <dest-host> --port <dest-port> --username <user> --password <password> --authenticationDatabase admin --oplogReplay <path-to-dump>/dump
If this doesn't not work for you, you may need to import oplog collection to a temporary db, and manipulate it to remove all except records for db5.