Introduction to Software Systems
  • About
  • Introduction
  • Software Engineering
    • Software System
    • Software Product Development
    • Computer Networks
  • Terminal Programming
    • BASH - Basic Commands
    • BASH - Conditions and Loops
    • Worked-out Examples
    • Practice Questions
  • Databases
    • Structured Databases
      • SQL Queries
      • Worked-out Example
    • Unstructured Databases
      • NoSQL Queries
      • Worked-out Example
  • Object Oriented Programming
    • Python - Introduction
    • Python - Basic Concepts
    • Python - Inbuilt Datastructures
    • Python - Conditions and Loops
    • Python - Lambda, Functions, Class/Objects
    • Worked-out Examples
  • WEB TECHNOLOGIES
    • HTML
    • CSS
    • Native JavaScript - Basics
    • Native JavaScript - Conditional Statements and Loops
    • Native JavaScript - Data Structures
    • JavaScript - Scope, Functions, Type Conversion
Powered by GitBook
On this page
  1. Databases
  2. Unstructured Databases

Worked-out Example

This page illustrates details step-by-step guide to implement NOSQL for creation of database, tables and eventually query them to obtain data.

PreviousNoSQL QueriesNextPython - Introduction

Last updated 3 months ago

Software Installation

  • Install MongoDB Shell for Windows or Ubuntoo from .

  • Install MongoDB Compass GUI for Windows or Ubuntoo from . This a GUI for MongoDB Shell software that helps the database user to review and analysis the datasets available in the database.

  • Instead you can directly use online compliers for practice. Try , ,

// Connect to MongoDB (assuming you're already connected)

// Create the Campus database if it doesn't exist
use("Campus");

// Define main collections
db.createCollection("campuses");
db.createCollection("departments");
db.createCollection("students");
db.createCollection("courses");

// Insert sample data into campuses collection
db.campuses.insertOne({
    name: "University of Tech",
    location: "Cityville",
    founded: 1950,
    website: "www.techuniversity.edu"
});

// Insert sample data into departments collection  
db.departments.insertMany([
    {name: "Computer Science", campusId: ObjectId("...")},
    {name: "Engineering", campusId: ObjectId("...")}
]);

// Insert sample data into students collection
db.students.insertOne({
    name: "John Doe",
    studentId: "S123456",
    department: ObjectId("..."),
    year: 3,
    gpa: 3.5
});

// Insert sample data into courses collection
db.courses.insertMany([
    {name: "Data Structures", campusId: ObjectId("..."), departmentId: ObjectId("...")},
    {name: "Algorithms", campusId: ObjectId("..."), departmentId: ObjectId("...")}
]);

//Insert 10 student information into students collection
db.students.insertMany([
  { name: "Alice Johnson", studentId: "S001", department: ObjectId("..."), year: 2, gpa: 3.8 },
  { name: "Bob Smith", studentId: "S002", department: ObjectId("..."), year: 3, gpa: 3.7 },
  { name: "Charlie Brown", studentId: "S003", department: ObjectId("..."), year: 1, gpa: 3.9 },
  { name: "David Lee", studentId: "S004", department: ObjectId("..."), year: 2, gpa: 3.6 },
  { name: "Eve Davis", studentId: "S005", department: ObjectId("..."), year: 3, gpa: 3.8 },
  { name: "Frank Williams", studentId: "S006", department: ObjectId("..."), year: 1, gpa: 3.7 },
  { name: "Grace Martin", studentId: "S007", department: ObjectId("..."), year: 2, gpa: 3.9 },
  { name: "Henry Thompson", studentId: "S008", department: ObjectId("..."), year: 3, gpa: 3.6 },
  { name: "Ivy Chen", studentId: "S009", department: ObjectId("..."), year: 1, gpa: 3.8 },
  { name: "Jack Harris", studentId: "S010", department: ObjectId("..."), year: 2, gpa: 3.7 }
]);

db.students.find();

here
here
OneCompiler
MyCompiler
Humongous Compiler