- Create a keyfile With keyfile authentication, each mongod instances in the replica set uses the contents of the keyfile as the shared password for authenticating other members in the deployment. Only mongod instances with the correct keyfile can join the replica set
openssl rand -base64 756 > <path-to-keyfile>
chmod 400 <path-to-keyfile>- Create a mongo replica set
# Run the mongod command with the --replSet and --keyFile flags
mongod --keyFile <path-to-keyfile> --replSet <replicaSetName>- Authenticate as administrator
mongosh --port 27016 -u adminuser -p mypassword --authenticationDatabase admin- Initialize the replica set
mongosh --port 27017
> rs.initiate()- Follow change stream tutorial