0

error_img config_27017 config_27020 I am trying to extract data from one db(running in port 27017) and storing the extracted data in another db(27020). for 1st db I have set auth but not for 2nd db. I have mongodb installed in aws instance. And I am Creating each database in different ports(i.e. 27017, 27020). Created separate mongo_config file for each port. Able to access newly created db from robo3T, However accessing collection gives below error:

**Error "ListCollection failed: {ok: 0.0, errmsg: "not authorized on <db> to execute command {listCollection:1, filter: {}, cursor: {}, $readPreference: {mode: "secondaryPreferred"}. $d..". code:13, codeName: "Unauthorized"}"}**

Please suggest me the steps to create 2 mongo instances, listening to 2 diff ports in one server.

  • The error is quite obvious. How do you connect? See https://stackoverflow.com/questions/63754742/authentication-failure-while-trying-to-save-to-mongodb/63755470#63755470 – Wernfried Domscheit Oct 22 '21 at 06:09
  • mongod --config /etc/mongod_two.conf mongo --port 27020 >show dbs is not showing any db. I did not create any user on mongodb running in 27020 port. but I do create user for admin db, when mongodb is running in 27017 port. – Himani Pandey Oct 23 '21 at 18:17
  • Why do you specify port in command line when you have a config file? Can you post your two config files? – Wernfried Domscheit Oct 23 '21 at 21:02
  • if i run without specifying port, it by default takes 27017 port and listing its db and coll. I have added both the config file img link above as [config_27017, config_27020]. Pls suggest me how can I access the db and collection of mongo running in port 27020. – Himani Pandey Oct 24 '21 at 16:27
  • Please don't paste screenshots, provide code and config file as formatted text. See https://meta.stackoverflow.com/a/285557/3027266 – Wernfried Domscheit Oct 24 '21 at 17:14
  • When you specify the port in config file, then you don't need `--port 27020` in command line. – Wernfried Domscheit Oct 24 '21 at 17:16
  • In config file you enabled authentication on both, i.e. the only permitted (or at least the only useful) command is `createUser()`. Either create a user or disable authentication. – Wernfried Domscheit Oct 24 '21 at 17:18
  • thanks for your continuous help @Wernfried Domscheit . After removing the auth from both the files, I am able to create the collection from mongo shell running in aws localhost. However not able to connect to mongodb 27020, when I am connecting from remote server or robo3T using cmd: – Himani Pandey Oct 25 '21 at 08:05
  • $ mongo mongodb://:27020 MongoDB shell version v5.0.3 connecting to: mongodb://:27020/?compressors=disabled&gssapiServiceName=mongodb Error: couldn't connect to server :27020, connection attempt failed: SocketException: Error connecting to :27020 :: caused by :: No connection could be made because the target machine actively refused it. : connect@src/mongo/shell/mongo.js:372:17 @(connect):2:6 exception: connect failed exiting with code 1 – Himani Pandey Oct 25 '21 at 08:06
  • inbound rules: IPv4 Custom TCP TCP 27020 0.0.0.0/0 – Himani Pandey Oct 25 '21 at 08:08
  • Did you check the mongod logfile? – Wernfried Domscheit Oct 25 '21 at 09:01

0 Answers0