Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 4

/* global use, db */

// MongoDB Playground
// Use Ctrl+Space inside a snippet or a string literal to trigger completions.

const database = 'StudentConsultationDB';

// Create a new database.


use(database);

// Create a new collection.


db.createCollection('consultation_details', {
validator: {
$jsonSchema: {
bsonType: 'object',
required: ['consultationId', 'lecturerId', 'date', 'timeMinutes',
'maximumNumberOfStudents', 'status', 'startTime', 'endTime'],
properties: {
consultationId: {
bsonType: 'int',
description: 'must be an integer'
},
lecturerId: {
bsonType: 'string',
description: 'must be a string'
},
date: {
bsonType: 'string',
description: 'must be a string representing date'
},
timeMinutes: {
bsonType: 'int',
description: 'must be an integer'
},
maximumNumberOfStudents: {
bsonType: 'int',
description: 'must be an integer'
},
status: {
bsonType: 'string',
description: 'must be a string'
},
startTime: {
bsonType: 'string',
description: 'must be a string representing time'
},
endTime: {
bsonType: 'string',
description: 'must be a string representing time'
},
}
},
}
});

// LecturerDetails
db.createCollection('lecturer_details', {
validator: {
$jsonSchema: {
bsonType: 'object',
required: ['lecturerId', 'firstName', 'lastName'],
properties: {
lecturerId: {
bsonType: 'string',
description: 'must be a string'
},
firstName: {
bsonType: 'string',
description: 'must be a string'
},
lastName: {
bsonType: 'string',
description: 'must be a string'
},
}
},
}
});

// ConsultationPeriods
db.createCollection('consultation_periods', {
validator: {
$jsonSchema: {
bsonType: 'object',
required: ['lecturerId', 'dayOfWeek', 'startTime', 'endTime',
'durationMinutes', 'maximumNumberOfConsultationsPerDay', 'numberOfStudents'],
properties: {
lecturerId: {
bsonType: 'string',
description: 'must be a string'
},
dayOfWeek: {
enum: ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday',
'Saturday', 'Sunday'],
description: 'must be a day of the week and is required'
},
startTime: {
bsonType: 'string',
description: 'must be a string representing time'
},
endTime: {
bsonType: 'string',
description: 'must be a string representing time'
},
durationMinutes: {
bsonType: 'int',
description: 'must be an integer'
},
maximumNumberOfConsultationsPerDay: {
bsonType: 'int',
description: 'must be an integer'
},
numberOfStudents: {
bsonType: 'int',
description: 'must be an integer'
},
}
},
}
});

// StudentBooking
db.createCollection('student_booking', {
validator: {
$jsonSchema: {
bsonType: 'object',
required: ['consultationId', 'studentEmailAddress', 'role'],
properties: {
consultationId: {
bsonType: 'int',
description: 'must be an integer'
},
studentEmailAddress: {
bsonType: 'string',
description: 'must be a string'
},
role: {
bsonType: 'string',
description: 'must be a string'
},
}
},
}
});

// StudentDetails
db.createCollection('student_details', {
validator: {
$jsonSchema: {
bsonType: 'object',
required: ['studentNumber', 'studentEmailAddress', 'firstName', 'lastName'],
properties: {
studentNumber: {
bsonType: 'string',
description: 'must be a string'
},
studentEmailAddress: {
bsonType: 'string',
description: 'must be a string'
},
firstName: {
bsonType: 'string',
description: 'must be a string'
},
lastName: {
bsonType: 'string',
description: 'must be a string'
},
}
},
}
});

// More information on the `createCollection` command and JSON schema validation


can be found at:
// https://www.mongodb.com/docs/manual/reference/method/db.createCollection/
// https://www.mongodb.com/docs/manual/core/schema-validation/

You might also like