pretendo-docker/scripts/run-in-container/mongodb-init.js
2024-01-14 11:30:25 -05:00

23 lines
621 B
JavaScript

try {
const status = rs.status();
if (status.hasOwnProperty("myState") && status.myState == 1) {
print("Replica set is already initiated. Exiting...");
quit();
}
} catch (error) {
print("Replica set not initiated. Proceeding...");
}
// Initiate the replica set. We need to set up the members like this because, by
// default, the first member uses the host 127.0.0.1, which causes the other
// servers to attempt to connect to their own loopback addresses.
rs.initiate({
_id: "rs",
members: [
{
_id: 0,
host: "mongodb:27017",
},
],
});