Skip to content

Commit

Permalink
refactor: add config for autoIndex
Browse files Browse the repository at this point in the history
  • Loading branch information
AlmogVC committed Dec 21, 2019
1 parent 5d7fbef commit d239a92
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/aliveSignal/aliveSignal.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const aliveSignalSchema: mongoose.Schema = new mongoose.Schema(
},
{
versionKey: false,
autoIndex: false,
autoIndex: config.db.autoIndex,
id: true,
toJSON: {
virtuals: true,
Expand Down
1 change: 1 addition & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const config = {
db: {
connectionString: `mongodb://${process.env.DB_SERVERS || 'localhost:27017'}/${process.env.KEEP_ALIVE_DB_NAME ||
'drop-box-keep-alive'}${process.env.DB_REPLICA_NAME ? `?replicaSet=${process.env.DB_REPLICA_NAME}` : ''}`,
autoIndex: process.env.MONGO_AUTO_INDEX === '1' || false,
},
cors: {
allowedOrigins: process.env.ALLOWED_ORIGINS ? process.env.ALLOWED_ORIGINS.split(',') : ['*'],
Expand Down
5 changes: 3 additions & 2 deletions src/service/service.model.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import * as mongoose from 'mongoose';
import IService from './service.interface';
import config from '../config';

const serviceSchema: mongoose.Schema = new mongoose.Schema(
{
name: {
type: String,
required: true,
unique: true,
index: true,
immutable: true,
},
lastContactDate: {
Expand All @@ -31,7 +33,7 @@ const serviceSchema: mongoose.Schema = new mongoose.Schema(
},
{
versionKey: false,
autoIndex: false,
autoIndex: config.db.autoIndex,
timestamps: { createdAt: true, updatedAt: true },
id: true,
toJSON: {
Expand All @@ -43,7 +45,6 @@ const serviceSchema: mongoose.Schema = new mongoose.Schema(
},
);

serviceSchema.index({ name: 1 });
const ServiceModel = mongoose.model<IService & mongoose.Document>('Service', serviceSchema);

export default ServiceModel;
2 changes: 1 addition & 1 deletion src/serviceHost/serviceHost.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const serviceHostSchema: mongoose.Schema = new mongoose.Schema(
},
{
versionKey: false,
autoIndex: false,
autoIndex: config.db.autoIndex,
timestamps: { createdAt: true },
id: true,
toJSON: {
Expand Down

0 comments on commit d239a92

Please sign in to comment.