Error Message: Unable to connect to a member of the replica set matching Secondary Preferred

Error Message: Unable to connect to a member of the replica set matching Secondary Preferred

Action:
When running my package manually by VS it executes succesfully, but when I run it by SQL Agent job I get the following error message:
      Unable to connect to a member of the replica set matching Secondary Preferred

Error Message:
An error occurred with the following error message: "Unable to connect to a member of the replica set matching Secondary Preferred".
Solution:

Something is blocking the access to the Mongo DB server on that machine. It's possible that you have a network or a firewall issue. Also, it's possible that the server IP is not whitelisted. Please contact your system administrator about it.