mongoDB Schema Design

I am having trouble designing schema for an app. The directions given by the client were :

Create a student schema with name, contact, subjects, class, society, year in mongo, such that: 1. each student can have multiple subjects and can be in a single class 2. Each student can be part of multiple or none societies. Also, societies may be dynamically changed during the student’s life cycle (ie. societies can be added or removed after the creation of Student).

I came up with this model until now, but I’m not sure it is correct.

const studentSchema = new Schema({
    name: {
        type: String,
    contact: {
        type: Number,
    subjects: [String],
    class: {
        type: String,
        required: true
    year: {
        type: Number,

Please guide me here!

I think it’s OK what you’re describing with this schema definition. The only thing that I’d check is whether the “contact” field should be a Number or a String.
What exactly is causing you hesitation?

Hi, thanks for your response. The thing I’m confused with is, like if I wanted to get all the students in a particular society (lets say ‘theatre’), so how can this be done?

Considering that it’s an array of String it would just be
db.students.find({societies: 'theatre'}).

Look at this quick sample that I’ve just setup: mongodb/workingwithdata/students_society_find.txt · main · Raymundo Vásquez Ruiz / SharedNotes · GitLab

It has 3 students and I search on a matching society.
I hope this helps :v:t4:

Ps: The documentation is really nice, take a look there as well

There should be a : in place of = in the societies part.

The reason why your schema is not working is that because its written with a JS code not JSON-ld code. To get a schema in JSON-ld code i found this tool that can generate a variety of different types of schemas for free, all i have to do is to choose the schema type, fill up my information and click generate schema and the tool will have the code ready for me to use, please check it out