Skip to content

Commit

Permalink
Merge pull request #87 from shikshalokam/master
Browse files Browse the repository at this point in the history
compound index added
  • Loading branch information
aks30 authored Jun 15, 2022
2 parents 1c78f82 + f1a24ea commit e4d9e52
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 5 deletions.
12 changes: 11 additions & 1 deletion config/dbConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,21 @@ var DB = function() {
return model;
};

const runCompoundIndex = function(modelName,opts) {
if (opts && opts.length > 0) {
for ( let indexPointer = 0 ; indexPointer < opts.length ; indexPointer++ ) {
let currentIndex = opts[indexPointer];
db.collection(modelName).createIndex(currentIndex.name, currentIndex.indexType);
}
}
}

return {
database: db,
createModel: createModel,
ObjectId: ObjectId,
models: db.models
models: db.models,
runCompoundIndex: runCompoundIndex
};
};

Expand Down
3 changes: 3 additions & 0 deletions generics/abstract.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ let Abstract = class Abstract {
constructor(schema) {
this.model = database.createModel(schema);
this.schema = schema.name;
if ( schema.compoundIndex && schema.compoundIndex.length > 0 ) {
database.runCompoundIndex(schema.name,schema.compoundIndex);
}

this.httpStatus = {
ok: 200,
Expand Down
8 changes: 7 additions & 1 deletion models/observationSubmissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,11 @@ module.exports = {
userRoleInformation : Object,
criteriaLevelReport : Boolean,
userProfile : Object
}
},
compoundIndex: [
{
"name" :{ observationId: 1, entityId: 1, submissionNumber:1 },
"indexType" : { unique: true }
}
]
};
8 changes: 7 additions & 1 deletion models/observations.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,11 @@ module.exports = {
type : Boolean,
index: true
}
}
},
compoundIndex: [
{
"name" :{ createdBy: 1, solutionId: 1 },
"indexType" : { unique: true }
}
]
};
3 changes: 2 additions & 1 deletion models/surveySubmissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ module.exports = {
surveyId: {
type: "ObjectId",
index: true,
required: true
required: true,
unique: true
},
createdBy: {
type: String,
Expand Down
8 changes: 7 additions & 1 deletion models/surveys.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,11 @@ module.exports = {
default : false,
type : Boolean
}
}
},
compoundIndex: [
{
"name" :{ createdBy: 1, solutionId: 1 },
"indexType" : { unique: true }
}
]
};

0 comments on commit e4d9e52

Please sign in to comment.