Skip to content

Updates to MongoDB Connection and Kubernetes #3117

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions kubernetes_app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ spec:
selector:
matchLabels:
app: web-editor
replicas: 3
replicas: 4
template:
metadata:
labels:
Expand Down Expand Up @@ -99,8 +99,8 @@ metadata:
name: web-editor-node
namespace: production
spec:
maxReplicas: 6
minReplicas: 2
maxReplicas: 9
minReplicas: 3
scaleTargetRef:
apiVersion: extensions/v1beta1
kind: Deployment
Expand Down
22 changes: 17 additions & 5 deletions server/previewServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,24 @@ const app = new Express();
// This also works if you take out the mongoose connection
// but i have no idea why
const mongoConnectionString = process.env.MONGO_URL;

// Connect to MongoDB
mongoose.Promise = global.Promise;
mongoose.connect(mongoConnectionString, {
useNewUrlParser: true,
useUnifiedTopology: true
});
const connectToMongoDB = async () => {
try {
await mongoose.connect(mongoConnectionString, {
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true,
useFindAndModify: false
});
} catch (error) {
console.error('Failed to connect to MongoDB: ', error);
process.exit(1);
}
};

connectToMongoDB();

mongoose.set('useCreateIndex', true);
mongoose.connection.on('error', () => {
console.error(
Expand Down
21 changes: 16 additions & 5 deletions server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,22 @@ app.use('/', passportRoutes);
require('./config/passport');

// Connect to MongoDB
mongoose.Promise = global.Promise;
mongoose.connect(mongoConnectionString, {
useNewUrlParser: true,
useUnifiedTopology: true
});
const connectToMongoDB = async () => {
try {
await mongoose.connect(mongoConnectionString, {
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true,
useFindAndModify: false
});
} catch (error) {
console.error('Failed to connect to MongoDB: ', error);
process.exit(1);
}
};

connectToMongoDB();

mongoose.set('useCreateIndex', true);
mongoose.connection.on('error', () => {
console.error(
Expand Down
Loading