PHP代写 | ISYS1101/ 1102 Database Applications

本次PHP代写是使用php与MongoDB实现一个网站

School/Department/Area
Document: Week 7 – Getting Started with MongoDB.docx
Author: Santha Sumanasekara
Save Date: 09/09/2019
Page 1 of 10
School of Science/ Computer Science and Information Technology
ISYS1101/ 1102 Database Applications
Week 7: Tute/Lab – Getting Started with MongoDB
Semester 2 2019
1 Objective
The objective of this tute/lab session is to explore the features of MongoDB, learn how to build a
document collection and retrieve data from a collection, and how to build a web database
application with MongoDB backend.
NoSQL databases, such as MongoDBÒ (mongodb.com), were created in response to the
limitations of traditional relational database technology. When compared against relational
databases, NoSQL databases are more scalable and provide superior performance, and their data
model addresses several shortcomings of the relational model.
The advantages of NoSQL include being able to handle:
• First and foremost, it is very easy to install and setup the MongoDB.
• The very basic feature of MongoDB is that it is a schema-less database. Since MongoDB is
schema-free, your code defines your schema.
• Large volumes of structured, semi-structured, and unstructured data;
• Agile development;
• Inherently secure because no sql injection can be made.
• Compared to RDBMS, NOSQL database systems are light-weight, very little overheads,
and, has a smaller memory footprint and as a result, provide a far superior performance.
• Horizontal scaling (sharding) – The support for Sharding is one of its key features. Sharding
is the process of storing the data in different machines and MongoDB’s ability to process
the data, as and when the size of the data grows. This results in the horizontal scaling.
• Replication — Auto data replication is also supported in NoSQL databases by default.
Hence, if one DB server goes down, data is restored using its copy created on another
server in network.
(https://www.studytonight.com/mongodb/advantages-of-mongodb)
Science of Science/ Computer Science and IT
Document: Week 7 – Getting Started with MongoDB.docx
Author: Santha Sumanasekara
Save Date: 05/09/2019
Page 2 of 10
Today, companies leverage NoSQL databases for a growing number of use cases. NoSQL
databases also tend to be open-source and that means a relatively low-cost way of developing,
implementing and sharing software.
Companies choose MongoDB for developing modern applications as it offers the advantages of
relational databases along with the innovations of NoSQL.
In the second half of the Database Application course, we explore the features of MongoDB, learn
how to build a document collection and retrieve data from a collection, and how to build a web
database application with MongoDB backend.
In the second assignment you will rebuild Facebook-Lite application you worked out in Assignment
1 using MongoDB backend. The activities in this tute/lab session will assist you to learn the basics
required to start your assignment work.
2 Preparation Tasks
MongoDB is not available on School’s servers or on mydesktop.rmit.edu.au. As outlined on the
course guide, you are required to install it on your personal computer (ideally, a mac, Linux or 64-
bit Windows).
If you do have prior experience in system administration and/or compiling and
installing new applications on your computer, you may choose to do your own
installation. However, if you choose to follow your own approach, we cannot help with
any troubleshooting with your setup.
To make your installation simple, platform-independent, and trouble-free, we use the Docker
(docker.com) platform. The MongoDB database server and a pre-configured web server are
installed as Docker containers. The client applications (MongoDB Compass and a web browser)
will run as native applications on your host computer.
Docker is a tool designed to make it easier to create, deploy, and run applications by using
containers. Containers allow a developer to package up an application with all of the parts it needs,
such as libraries and other dependencies, and ship it all out as one package.
In a way, Docker is a bit like a virtual machine. But unlike a virtual machine, rather than creating a
whole virtual operating system, Docker allows applications to use the host computer as the system
that they’re running on and only requires applications be shipped with things not already running
on the host computer. This gives a significant performance boost and reduces the size of the
application.
Another major advantage is that these containers are platform-independent and will work
anywhere that you can install (and run) Docker application.
For this part of the course we use two Docker containers – a MongoDB database container and a
customised Nginx web server container with php and MongoDB module for php. They are
organised as follows:
Science of Science/ Computer Science and IT
Document: Week 7 – Getting Started with MongoDB.docx
Author: Santha Sumanasekara
Save Date: 05/09/2019
Page 3 of 10
2.1 Installing Docker Desktop
In order to run applications within docker containers, you must have the Docker Desktop installed
on your host computer. This application is available for 64-bit Windows, Linux and Mac. Download
it from hub.docker.com and install it.
You will be required to create a “free” account on Docker Hub. Docker Hub has thousands of prebuilt docker containers, as well.
On some rare instances (we have found some Microsoft Surface laptops experience this problem),
some laptops require changes to BIOS settings enabled to run virtualisation software, like Docker
Desktop. https://blogs.technet.microsoft.com/canitpro/2015/09/08/step-by-step-enabling-hyper-vfor-use-on-windows-10/
If you get an error message – “This computer doesn’t have VT-X/AMD-v enabled. Enabling it in the
BIOS is mandatory” – You may have to follow the instructions given on the above webpage.
If you encounter this (rare) problem, your Lab assistant will show you how to tweak
BIOS settings.
When the Docker Desktop is up and running,
On Mac, you will see the Docker icon on the top menu bar.
Also, you can check information and the version of your Docker Desktop, on the command prompt:
$ docker version
$ docker info
Science of Science/ Computer Science and IT
Document: Week 7 – Getting Started with MongoDB.docx
Author: Santha Sumanasekara
Save Date: 05/09/2019
Page 4 of 10
For more information on running Docker Desktop on Mac, visit:
https://docs.docker.com/docker-for-mac/
On Windows,
Open a terminal window (Command Prompt or PowerShell, but not PowerShell ISE), and run
> docker version
> docker info
For more information on running Docker Desktop on Windows, visit:
https://docs.docker.com/docker-for-windows/
2.2 Installing MongoDB and a pre-configured web server on Docker
On Docker Hub, you will find there are pre-built containers for MongoDB and Nginx web server.
However, they are not customised to communicate each other – off the shelf, and require some
configurations. However, there is a community-built customised MongoDB + Nginx + PHP
container is available at: https://github.com/nanoninja/docker-nginx-php-mongo
On this github page, there is an icon for “Clone or download” the repository. Create a new folder
and download it as a zip file.
$ mkdir mongo
$ cd mongo
$ unzip docker-nginx-php-mongo-master.zip
This will create a sub-folder called “docker-nginx-php-mongo-master”. Change to this folder, and
run the following command.
$ cd docker-nginx-php-mongo-master
$ docker-compose up -d
It will build the docker container, by downloading required items from their sources and configuring
the container as per config file “docker-compose.yml”.
Now your docker setup is complete. Test it out on a browser window on your host computer, by
typing:
http://localhost:8000
If your set up is complete, a test page should be displayed.
Science of Science/ Computer Science and IT
Document: Week 7 – Getting Started with MongoDB.docx
Author: Santha Sumanasekara
Save Date: 05/09/2019
Page 5 of 10
2.3 Installing MongoDB Compass on host computer
The last step on your setup is to install MongoDB Compass Community Edition. MongoDB
Compass is the GUI for MongoDB. It allows you to visually explore your data, run ad-hoc queries,
and interact with your data with full CRUD functionality.
The most recent MongoDB Compass Community Edition is available at:
https://www.mongodb.com/products/compass
Download and install it, by following the normal application installation process for your operating
system.
2.4 Connecting the MongoDB (on Docker container) from MongoDB
Compass on host computer
The MongoDB on the Docker Container had been configured to listen to port 27020 (the default
MongoDB port is 27017. Within the container, we use this port. If any request is made from the
host computer, port 27020 is used.
Open MongoDB Compass and enter the following login details.
Host: localhost
Port: 27020
Authentication: None
Leave the default values for other fields.
Science of Science/ Computer Science and IT
Document: Week 7 – Getting Started with MongoDB.docx
Author: Santha Sumanasekara
Save Date: 05/09/2019
Page 6 of 10
If successful, you will be presented with the database workbench, similar to:
3 Working with MongoDB
3.1 Creating a small document collection
In this activity, we create a new database and a new document collection and populate it with few
documents.
Open MongoDB Compass, on the main window, click the “Create Database” button at the bottom
left corner (Hover the mouse over “+” symbol).
On the “Create Database” dialog box, enter
Database Name: MyDB
Collection Name: MyUsersCollection
Leave the tick boxes unticked
Science of Science/ Computer Science and IT
Document: Week 7 – Getting Started with MongoDB.docx
Author: Santha Sumanasekara
Save Date: 05/09/2019
Page 7 of 10
The new database with a new blank collection should appear on database list.
Click on “Insert Document” button to insert a new document.
When clicked, a document insertion template will appear with the document number already
generated.
Populate the template with the following data. You are required to enter both field name AND data
for the field.
The new document should appear on your document browser window:
Science of Science/ Computer Science and IT
Document: Week 7 – Getting Started with MongoDB.docx
Author: Santha Sumanasekara
Save Date: 05/09/2019
Page 8 of 10
Insert another document. This time, with Name, State, and Telephone.
Did you already notice a difference between (schema-based) relational database model and
(schema-less) NOSQL model?
You can browse the document collection, either as a list or table:
3.2 Access the document collection using a PHP script.
In this activity, we test the web connectivity (between MongoDB server and Nginx/php web server.
They both reside within the same docker container. Within the container, MongoDB listens to port
27017 (default port). So, php script connects to the database using this port.
Download the read_MyDB_MyUsersCollection.php file from the Canvas (Week 7 module) and
save it onto <docker-Home>/web/public directory.
Open it on a web browser. Do you see the two documents you just inserted?
http://localhost:8000/read_MyDB_MyUsersCollection.php
Science of Science/ Computer Science and IT
Document: Week 7 – Getting Started with MongoDB.docx
Author: Santha Sumanasekara
Save Date: 05/09/2019
Page 9 of 10
We will discuss the database connectivity elements in this PHP script in the next week’s lab
session.
Science of Science/ Computer Science and IT
Document: Week
7
– Getting Started with MongoDB.do
c
x
Author: Santha Sumanasekara
Save Date: 05/0
9/2019
Page 10 of 10


程序代写代做C/C++/JAVA/安卓/PYTHON/留学生/PHP/APP开发/MATLAB


本网站支持淘宝 支付宝 微信支付  paypal等等交易。如果不放心可以用淘宝交易!

E-mail: [email protected]  微信:dmxyzl003


如果您使用手机请先保存二维码,微信识别。如果用电脑,直接掏出手机果断扫描。

发表评论