Skip to content
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

Mongodb replica set #8

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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: 6 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,9 @@ ELASTICSEARCH_HOST_URL = "http://127.0.0.1:9200"
ELASTICSEARCH_ENTITIES_INDEX = "entities" // Elastic search index name for storing entities

USER_SERVICE_URL = "http://user-service:3000" // Base url of the sunbird enviornment

# Replica set name required for mongodb replicaSets
REPLICA_SET_NAME = "rs0"

# Replica set read preference
REPLICA_SET_READ_PREFERENCE = "primary"
22 changes: 15 additions & 7 deletions config/db/mongodb.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,33 @@ var databaseConfiguration = function () {
mongoose.set('useCreateIndex', true);
mongoose.set('useFindAndModify', false);
mongoose.set('useUnifiedTopology', true);

let options = {useNewUrlParser: true};

if (process.env.REPLICA_SET_NAME && process.env.REPLICA_SET_NAME !== "") {
options["replset"] = {rs_name: process.env.REPLICA_SET_NAME };

if (process.env.REPLICA_SET_READ_PREFERENCE && process.env.REPLICA_SET_READ_PREFERENCE !== "") {
options["replset"]["readPreference"] = process.env.readPreference;
}
}

var db = mongoose.createConnection(
process.env.MONGODB_URL,
{
useNewUrlParser: true
}
options
);

db.on("error", console.error.bind(console, "connection error:"));
db.once("open", function () {
console.log("Connected to database!");
});

let schema = {};
var createModel = function (opts) {
if (typeof opts.schema.__proto__.instanceOfSchema === "undefined") {
var schema = mongoose.Schema(opts.schema, opts.options);
schema = mongoose.Schema(opts.schema, opts.options);
} else {
var schema = opts.schema;
schema = opts.schema;
}

schema.plugin(mongooseTimeStamp, {
Expand All @@ -66,8 +75,7 @@ var databaseConfiguration = function () {
}
}

var model = db.model(opts.name, schema, opts.name);
return model;
return db.model(opts.name, schema, opts.name);
};

return {
Expand Down
2 changes: 0 additions & 2 deletions controllers/v1/cloud-services/aws.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ module.exports = class Aws {
* @apiSuccess {String} result Data
*/

constructor() { }

static get name() {
return "aws";
}
Expand Down
2 changes: 0 additions & 2 deletions controllers/v1/cloud-services/azure.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ module.exports = class Azure {
* @apiSuccess {String} result Data
*/

constructor() { }

static get name() {
return "azure";
}
Expand Down
2 changes: 0 additions & 2 deletions controllers/v1/cloud-services/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ module.exports = class Files {
* @apiSuccess {String} result Data
*/

constructor() { }

static get name() {
return "files";
}
Expand Down
2 changes: 0 additions & 2 deletions controllers/v1/cloud-services/gcp.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ module.exports = class Gcp {
* @apiSuccess {String} result Data
*/

constructor() { }

static get name() {
return "gcp";
}
Expand Down
3 changes: 0 additions & 3 deletions generics/constants/api-responses.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ module.exports = {
"QR_CODE_INCORRECT" : "Some code is incorrect",
"QR_CODE_NOT_FOUND" : "No qr code found",
"QR_CODE_FETCHED" : "Qr code information fetched successfully",
"QR_CODE_EXISTS" : "Qr code already exists",
"QR_CODE_DATA_NOT_FOUND" : "Data for qr code not found",
"SUNBIRD_SERVICE_DOWN" : "Could not connect to bodh service",
"DIAL_CODE_NOT_PUBLISHED" : "Dial code is not published",
Expand Down Expand Up @@ -97,7 +96,6 @@ module.exports = {
"SOLUTION_UPDATED" : "Solution updated successfully",
"USER_ROLES_FETCHED" : "Successfully fetched user roles",
"STATE_NOT_FOUND" : "State could not found",
"SUB_ENTITY_NOT_FOUND" : "Could not found sub entity",
"USER_ROLES_NOT_FOUND" : "Could not found user roles",
"ENTITIES_MAPPING_FORM_FETCHED" : "Entities mapping form fetched successfully",
"USER_DATA_EXISTS" : "User data exists",
Expand Down Expand Up @@ -130,7 +128,6 @@ module.exports = {
"ERROR_CREATING_PROGRAM" : "Error creating program",
"PROGRAM_NOT_FOUND" : "Program not found" ,
"PROGRAM_EXIST" : "Program exist",
"PROGRAM_DESCRIPTION" : "Program description",
"USER_TARGETED_PROGRAMS_FETCHED" : "Users programs fetched successfully",
"USER_TARGETED_SOLUTIONS_FETCHED" : "Users solutions fetched successfully",
"ROLE_REQUIRED_IN_SCOPE" : "Required role in scope",
Expand Down
1 change: 0 additions & 1 deletion generics/constants/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ module.exports = {
"ALL_APP_VERSION" : "allAppVersion",
"ACTIVE" : "active",
"IN_ACTIVE" : "inactive",
"BODH_DIAL_CODE_LIVE_STATUS" : "Live",
"GOA_STATE" : "Goa",
"UNNATI_APP_NAME" : "unnati",
"PROFILE_UPDATE_NOTIFICATION_MESSAGE":"Please update your details.Help us make your experience better.",
Expand Down
5 changes: 1 addition & 4 deletions generics/helpers/elastic-search.js
Original file line number Diff line number Diff line change
Expand Up @@ -743,10 +743,7 @@ var getLanguageData = function (languageId = "") {

if (languageId == "") throw new Error("Invalid language id.");

const languageDocument = await getData(languageId, {
index: COMMON_LANGUAGE_INDEX,
type: COMMON_LANGUGAE_TYPE
});
const languageDocument = await getData(languageId);

return resolve(languageDocument);

Expand Down
1 change: 0 additions & 1 deletion models/programs.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ module.exports = {
createdFor: [String],
imageCompression: {},
components: ["json"],
components: ["json"],
isAPrivateProgram : {
default : false,
type : Boolean
Expand Down
2 changes: 0 additions & 2 deletions models/solutions.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,9 @@ module.exports = {
registry: Array,
frameworkId: "ObjectId",
frameworkExternalId: String,
parentSolutionId: "ObjectId",
noOfRatingLevels: Number,
isRubricDriven: { type : Boolean, default: false },
enableQuestionReadOut: { type : Boolean, default: false },
isReusable: Boolean,
roles: Object,
observationMetaFormKey: String,
updatedBy: String,
Expand Down
2 changes: 1 addition & 1 deletion module/entityTypes/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ module.exports = class EntityTypesHelper {
});
}

if( skipFields !== "none" ) {
if( skipFields != "none" ) {
skipFields.forEach(field=>{
projection[field] = 0;
})
Expand Down
2 changes: 1 addition & 1 deletion module/files/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ module.exports = class FilesHelper {

let cloudStorage = process.env.CLOUD_STORAGE

if (storageName !== '') {
if (storageName != '') {
cloudStorage = storageName
}

Expand Down
2 changes: 1 addition & 1 deletion module/forms/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module.exports = class FormHelper {
});
}

if( skipFields !== "none" ) {
if( skipFields != "none" ) {
skipFields.forEach(field=>{
projection[field] = 0;
})
Expand Down
2 changes: 1 addition & 1 deletion module/programs/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ module.exports = class ProgramsHelper {
});
}

if( skipFields !== "none" ) {
if( skipFields != "none" ) {
skipFields.forEach(field=>{
projection[field] = 0;
})
Expand Down
2 changes: 1 addition & 1 deletion module/solutions/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ module.exports = class SolutionsHelper {
});
}

if( skipFields !== "none" ) {
if( skipFields != "none" ) {
skipFields.forEach(field=>{
projection[field] = 0;
})
Expand Down
2 changes: 1 addition & 1 deletion module/static-links/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ module.exports = class StaticLinksHelper {
});
}

if (skipFields !== "none") {
if (skipFields != "none") {
skipFields.forEach(field => {
projection[field] = 0;
})
Expand Down
2 changes: 1 addition & 1 deletion module/user-profile/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module.exports = class UserProfileHelper {
return new Promise(async (resolve, reject) => {
try {

if( queryParameter === "all" ) {
if( queryParameter == "all" ) {
queryParameter = {};
};

Expand Down
4 changes: 2 additions & 2 deletions module/user-profile/validator/v1.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ module.exports = (req) => {
let userProfileValidator = {

getForm : function() {
req.checkHeaders('appname').exists().withMessage("required app name in headers"),
req.checkHeaders('os').exists().withMessage('required os in headers')
req.checkHeaders('appname').exists().withMessage("required app name in headers");
req.checkHeaders('os').exists().withMessage('required os in headers');
},
save: function () {
req.checkBody('data').exists().withMessage("Required meta information data");
Expand Down
2 changes: 1 addition & 1 deletion module/user-roles/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ module.exports = class UserRolesHelper {
});
}

if( skipFields !== "none" ) {
if( skipFields != "none" ) {
skipFields.forEach(field=>{
projection[field] = 0;
})
Expand Down
1 change: 0 additions & 1 deletion routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ module.exports = function (app) {
message: result.message,
status: result.status ? result.status : httpStatusCode["ok"].status,
result: result.data,
result: result.result,
additionalDetails: result.additionalDetails,
pagination: result.pagination,
totalCount: result.totalCount,
Expand Down