> For the complete documentation index, see [llms.txt](https://sai11101989.gitbook.io/iss_workbook/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://sai11101989.gitbook.io/iss_workbook/databases/unstructured-databases/worked-out-example.md).

# 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.

#### Software Installation

* Install MongoDB Shell for Windows or Ubuntoo from [here](https://www.mongodb.com/try/download/shell).&#x20;
* Install MongoDB Compass GUI for Windows or Ubuntoo from [here](https://www.mongodb.com/try/download/compass). 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 [OneCompiler](https://onecompiler.com/mongodb), [MyCompiler](https://www.mycompiler.io/new/mongodb), [Humongous Compiler](https://www.humongous.io/tools/playground/mongodb/new)

```sql
// 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();

```
