Skip to content

Instantly share code, notes, and snippets.

@sanatcodes
Last active April 24, 2025 08:25
Show Gist options
  • Save sanatcodes/874d69b36f9a81aa1487b5770598ebdb to your computer and use it in GitHub Desktop.
Save sanatcodes/874d69b36f9a81aa1487b5770598ebdb to your computer and use it in GitHub Desktop.
Setup MongoDB replica set on local host with only a single primary - For Apple Silicon
Add the `replication` section to the mongod.conf file:
```
$cat /opt/homebrew/etc/mongod.conf
systemLog:
destination: file
path: /opt/homebrew/var/log/mongodb/mongo.log
logAppend: true
storage:
dbPath: /opt/homebrew/var/mongodb
net:
bindIp: 127.0.0.1, ::1
ipv6: true
replication:
replSetName: replocal
```
Restart mongod using brew(change @__ according to your version):
```sh
$ brew services restart [email protected]
```
Connect with local mongo shell and initiate the replica set:
```
$mongo
> rs.initiate({_id: "replocal", members: [{_id: 0, host: "127.0.0.1:27017"}] })
{ "ok" : 1 }
```
Now you'll be secondary, but then it will promote you to primary since you're the only one:
```
replocal:SECONDARY> rs.status
function () {
return db._adminCommand("replSetGetStatus");
}
replocal:PRIMARY> rs.status()
```
You can tail the oplog at
```
replocal:PRIMARY> use local
switched to db local
replocal:PRIMARY> db.getCollection('oplog.rs').find()
```
...lots of output here
@sanatcodes
Copy link
Author

This is an updated version of this gist from Davisford. It is specifically for Apple Silicon architecture.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment