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:
An error occurred with the following error message: "Unable to connect to a member of the replica set matching Secondary Preferred".
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.