131k views
3 votes
1. The BackEnd application run as web server using express having a REST API, should use mongoDB queries to demonstrate following:

1.1 Create a Mongo dB collection to hold the data from the given CSV file. name this collection as Covid Data or any appropriate name.

1.2 Create mongoose Schema in a JS separate file (Name it as of your choice) for this dataset and from this Schema create a model to be used in add, delete, update and find queries.

1.3 Create another file (name it as of your choice) import the file that you uses mongoose Schema created in 1.2 and make connection with mongoDB

1.4 Create a separate JS file (server.js ) that runs a web server using express and import the files created in 1.2 and 1.3 Add the code in Server.js as required in the following :

1.5 , Add a Query in a POST method of the REST API that should be able to Add the data i.e. • number of cases, • deaths , • state, and • date to the Covid collection in mongoDB

1.6. Add Query in a separate POST method for update case, death and date for a given state.

1.7 It should also have an separate Get method to show total number of cases & deaths for a given state

1.8 It should also have an separate endpoint using POST method for deleting a record for a document i.e. cases and deaths for given state

1.9 it should have an endpoint to having a Query to display first 20 record from the Covid data for a given state having number of deaths greater than a given value entered by the user . the data should be displayed on browser.

1 Answer

2 votes

Final Answer:

The BackEnd application run as web server using express having a REST API. 1.1 To create a MongoDB collection named "CovidData" to hold the data from the given CSV file, use the command: `db.createCollection("CovidData")`.

1.2 Create a mongoose Schema in a separate JS file, for example, "CovidSchema.js," and define a model to be used in queries for adding, deleting, updating, and finding data.

1.3 In another file, say "DatabaseConnection.js," import the mongoose Schema created in 1.2 and establish a connection with MongoDB using `mongoose.connect()`.

1.4 In the "server.js" file, run a web server using Express. Import the files created in 1.2 and 1.3, and configure the necessary routes and middleware.

1.5 Add a POST method in the REST API that uses the created model to add data (number of cases, deaths, state, and date) to the "CovidData" collection in MongoDB.

1.6 Implement a separate POST method for updating cases, deaths, and date for a given state using the model and Schema created earlier.

1.7 Create a separate GET method to show the total number of cases and deaths for a given state by querying the "CovidData" collection.

1.8 Implement a POST method for deleting a record (cases and deaths) for a given state using the model and Schema.

1.9 Add an endpoint with a POST method to display the first 20 records from the "CovidData" collection for a given state where the number of deaths is greater than a specified value entered by the user.

Step-by-step explanation:

The provided steps guide the development of a Node.js application using Express and MongoDB to handle COVID-19 data. Steps 1.1 to 1.4 involve setting up the database, schema, and server. Steps 1.5 to 1.8 describe adding, updating, retrieving, and deleting data using the REST API. Step 1.9 specifies an endpoint for displaying filtered data based on user input.

In this scenario, MongoDB is chosen for its flexibility with JSON-like documents, suitable for storing COVID-19 data. Mongoose, a MongoDB object modeling tool, facilitates schema creation and provides a straightforward way to interact with the database in a Node.js environment. Express simplifies the creation of a web server, handling routes and middleware efficiently.

The described architecture aligns with common practices in Node.js application development, emphasizing modularization, separation of concerns, and adherence to RESTful principles. The combination of MongoDB, Mongoose, and Express forms a robust stack for building scalable and maintainable web applications, particularly suited for handling data-centric operations like those related to COVID-19 statistics.

User Abror Esonaliev
by
6.9k points