ISYS1101/1102 Assignment 2: Creating a MongoDB Web Application

Verified

Added on  2022/09/28

|7
|478
|21
Practical Assignment
AI Summary
This assignment solution details the creation of a web application utilizing a MongoDB backend and PHP. The solution includes the creation of a database named "facebookDB" with three collections: users, posts, and friends. The PHP implementation defines database connections within a functions.php file, demonstrating the integration of MongoDB with a web application. The solution also includes examples of inserting data and fetching records. A key aspect highlighted is the flexibility of MongoDB compared to SQL, particularly in terms of schema-less design and simpler syntax. The assignment shows the advantages of NoSQL databases, such as ease of use and adaptability when adding new data fields. The solution provides a practical demonstration of building a web application with a MongoDB backend, emphasizing the differences between SQL and NoSQL approaches to database management and the benefits of MongoDB's flexibility.
tabler-icon-diamond-filled.svg

Contribute Materials

Your contribution can guide someone’s learning journey. Share your documents today.
Document Page
MongoDB:
Database created with the name – “facebookDB”
Three collections defined:
db.users.insert({
user_email: 'James@gmai.com',
user_firstname: 'James',
user_lastname: 'Wells',
user_nickname: 'Jimmy',
user_password: 'james123',
user_gender: 'Male',
user_birthdate: new Date(1999,11,10,2,35),
user_status: 'Active',
user_location: 'Sydney',
visibility_level: 'ALL'
});
db.posts.insert({
post_id:'1',
post_caption:'World changes',
post_time:'2019/10/10',
post_by:'test1@gmail.com'
});
db.friends.insert({
user1_email:'test1@gmail.com',
user2_email:'test2@gmail.com',
friendship_status:0
tabler-icon-diamond-filled.svg

Secure Best Marks with AI Grader

Need help grading? Try our AI Grader for instant feedback on your assignments.
Document Page
});
db.friends.insert({
user1_email:'test3@gmail.com',
user2_email:'test2@gmail.com',
friendship_status:0
});
In PHP:
In function directory there is a file functions.php:
The connections are defined here: (install composer and replace the highlighted in yellow with the
user name of your PC: (first navigate to that path and check you have autoload present)
Document Page
On My PC: mongpdb is configured on port 27017, change if you have different port.
If both things are correct then page will be loaded properly:
Document Page
Profile Page:
tabler-icon-diamond-filled.svg

Secure Best Marks with AI Grader

Need help grading? Try our AI Grader for instant feedback on your assignments.
Document Page
When post is added:
Document Page
Document Page
Difference between the two implementations:
In SQL it is mandatory to follow the define structure of the table and also before using any table, the
table must be define else it will throw errors. So in last assignment the project is done using SQL and
before working on the website we made sure that database and tables are created in prior.
But while working with MongoDB we have not bother about the database creation and collection (table)
creation. It has by itself created the database when we have referred in the code and also we have
directly inserted document without creating the collection and based on the data the collection is
created. This has simplified the working and reduce the overhead of binding with the schema.
Also with MongoDB if we need to add one more column in the table then we just have to pass that
value and automatically that column will be integrated with that particular document and if that column
is not present in one document and present in another document then also it not throwing any errors.
Hence NoSQL has provided more flexibility as compared to SQL and also if we check the syntax wise
then syntax are simple and within the document we can have another document. For fetching the
records we can directly user cursor and use direct method for fetching and no need to write long queries
with joins.
chevron_up_icon
1 out of 7
circle_padding
hide_on_mobile
zoom_out_icon
logo.png

Your All-in-One AI-Powered Toolkit for Academic Success.

Available 24*7 on WhatsApp / Email

[object Object]