db.createCollection("examStudent")


db.examStudent.insertOne({
    id: 1001,
    firstName: "Daniel",
    lastName: "Brown",
    dob: new Date("2005-03-15"),
    gender: "Male",
    email: "daniel.brown@example.com",
    address: {
        street: "12 Main Street",
        town: "Spanish Town",
        parish: "St Catherine"
    },
    phone: ["876-555-1001"],
    school: "St Catherine High",
    subject: ["Mathematics", "English", "Computer Science"]
});

db.examStudent.insertOne({
    id: 1002,
    firstName: "Alicia",
    lastName: "Williams",
    dob: new Date("2006-08-22"),
    gender: "Female",
    school: "Spanish Town High",
    subject: ["Mathematics", "Biology", "Chemistry"]
});

db.examStudent.insertOne({
    id: 1003,
    firstName: "Marcus",
    lastName: "Johnson",
    dob: new Date("2005-11-09"),
    gender: "Male",
    email: "marcus.johnson@example.com",
    phone: ["876-555-1003", "876-555-2003"],
    school: "Wolmer's Boys",
    subject: ["English", "Mathematics", "Physics"]
});

db.examStudent.insertOne({
    id: 1004,
    firstName: "Keisha",
    lastName: "Anderson",
    dob: new Date("2006-01-17"),
    gender: "Female",
    address: {
        street: "8 Church Road",
        town: "Kingston",
        parish: "Kingston"
    },
    school: "Campion College",
    subject: ["Mathematics", "English", "Information Technology"]
});

db.examStudent.insertOne({
    id: 1005,
    firstName: "Andre",
    lastName: "Thompson",
    dob: new Date("2005-07-30"),
    gender: "Male",
    school: "St Catherine High",
    subject: ["English", "Physics", "Mathematics"]
});

db.examStudent.insertOne({
    id: 1006,
    firstName: "Janelle",
    lastName: "Clarke",
    dob: new Date("2006-12-05"),
    gender: "Female",
    email: "janelle.clarke@example.com",
    school: "Spanish Town High",
    subject: ["Biology", "Chemistry", "Mathematics"]
});
db.examStudent.find()


db.examStudent.insertMany([
    {
        id: 1007,
        firstName: "Nathan",
        lastName: "Campbell",
        dob: new Date("2005-04-12"),
        gender: "Male",
        school: "Wolmer's Boys",
        subject: ["Mathematics", "Physics", "English"]
    },
    {
        id: 1008,
        firstName: "Shanice",
        lastName: "Robinson",
        dob: new Date("2006-09-19"),
        gender: "Female",
        email: "shanice.robinson@example.com",
        school: "Campion College",
        subject: ["Biology", "Chemistry", "Mathematics"],
        phone: ["876-555-1008"]
    },
    {
        id: 1009,
        firstName: "Kemar",
        lastName: "Morgan",
        dob: new Date("2005-02-25"),
        gender: "Male",
        school: "Spanish Town High",
        subject: ["Computer Science", "Mathematics", "English"]
    },
    {
        id: 1010,
        firstName: "Tiana",
        lastName: "Edwards",
        dob: new Date("2006-06-11"),
        gender: "Female",
        address: {
            street: "15 King Street",
            town: "Spanish Town",
            parish: "St Catherine"
        },
        school: "St Catherine High",
        subject: ["English", "Biology", "Mathematics"]
    },
    {
        id: 1011,
        firstName: "Dwayne",
        lastName: "Foster",
        dob: new Date("2005-10-03"),
        school: "Wolmer's Boys",
        subject: ["Physics", "Mathematics", "Computer Science"]
    },
    {
        id: 1012,
        firstName: "Renee",
        lastName: "Thomas",
        dob: new Date("2006-12-28"),
        gender: "Female",
        email: "renee.thomas@example.com",
        school: "Campion College",
        subject: ["Chemistry", "Biology", "English"]
    }
]);

db.examStudent.countDocuments()


db.examStudent.find().limit(4)


db.examStudent.find(
    {},
    {
        _id: 0,
        firstName: 1,
        lastName: 1,
        gender: 1,
        dob: 1,
        school: 1
    }
).limit(4)


db.examStudent.find().sort({ lastName: -1 }).limit(3)


db.examStudent.find(
    {},
    {
        _id: 0,
        firstName: 1,
        lastName: 1,
        school: 1
    }
).sort({ lastName: -1 }).limit(3)


db.examStudent.find(
    {},
    {
        _id: 0,
        firstName: 1,
        lastName: 1,
        school: 1
    }
).sort({ lastName: -1 }).limit(3)

db.examStudent.countDocuments({ gender: "Male" })

db.examStudent.countDocuments({ gender: "Female" })

db.examStudent.countDocuments({ gender: { $exists: false } })

db.examStudent.find(
    {
        $or: [
            { school: "St Catherine High" },
            { school: "Spanish Town High" }
        ]
    },
    {
        _id: 0,
        firstName: 1,
        lastName: 1,
        dob: 1,
        school: 1
    }
)


db.examStudent.find(
    {
        school: {
            $in: ["St Catherine High", "Spanish Town High"]
        }
    },
    {
        _id: 0,
        firstName: 1,
        lastName: 1,
        dob: 1,
        school: 1
    }
)


db.examStudent.find(
    {
        id: {
            $gte: 1003,
            $lte: 1008
        }
    },
    {
        _id: 0,
        firstName: 1,
        lastName: 1,
        dob: 1,
        school: 1
    }
)

db.examStudent.updateOne(
    { id: 1001 },
    {
        $set: {
            email: "daniel.new@example.com",
            phone: ["876-555-9999"]
        }
    }
)

db.examStudent.find(
    { id: 1001 },
    { _id: 0, firstName: 1, lastName: 1, email: 1, phone: 1 }
)

db.examStudent.updateMany(
    { school: "Campion College" },
    {
        $addToSet: {
            subject: "Information Technology"
        }
    }
)

db.examStudent.find(
    { school: "Campion College" },
    {
        _id: 0,
        firstName: 1,
        lastName: 1,
        subject: 1
    }
)

db.examStudent.deleteOne(
    { id: 1007 }
)

db.examStudent.find(
    { id: 1007 }
)

db.examStudent.deleteMany({
    $or: [
        { id: 1011 },
        { id: 1012 }
    ]
})

db.examStudent.find({
    id: { $gte: 1011, $lte: 1012 }
})



db.examStudentCopy.insertMany(
    db.examStudent.find(
        {},
        {
            _id: 0,
            id: 1,
            firstName: 1,
            lastName: 1,
            dob: 1,
            school: 1,
            subject: 1
        }
    ).toArray()
)

db.examStudentCopy.find()
db.examStudentCopy.countDocuments()

db.examStudent.find(
    {
        $expr: {
            $ne: [
                { $month: "$dob" },
                8
            ]
        }
    },
    {
        _id: 0,
        firstName: 1,
        lastName: 1,
        gender: 1,
        dob: 1
    }
)


function displayStudentStatement(firstName, lastName, subjects) {
    print("Student Statement");
    print("------------------------");
    print("Student Name: " + firstName + " " + lastName);
    print("Number of Subjects: " + subjects.length);
    print("Subjects: " + subjects.join(", "));
}

// Example function call
displayStudentStatement(
    "Daniel",
    "Brown",
    ["Mathematics", "English", "Computer Science"]
);

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: