0% found this document useful (0 votes)
22 views8 pages

mern_lab_program_ans

The document provides instructions for various programming tasks including creating a MongoDB database, performing insert and update operations, building a basic React app to display 'Hello World', and writing Node.js programs. It details the commands and code snippets required for each task, emphasizing the use of MongoDB, React, and Node.js. Additionally, some tasks are repeated, indicating similar solutions for different sections.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views8 pages

mern_lab_program_ans

The document provides instructions for various programming tasks including creating a MongoDB database, performing insert and update operations, building a basic React app to display 'Hello World', and writing Node.js programs. It details the commands and code snippets required for each task, emphasizing the use of MongoDB, React, and Node.js. Additionally, some tasks are repeated, indicating similar solutions for different sections.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

1)(b). Create database in mongodb and perform insert, update operations ?

Ans)

# creating database in mongodb


> use companyDB;
# creating a collection
> db.createCollection("employees")

# inserting data
db.employees.insertOne({
name: "John Doe",
position: "Software Engineer",
salary: 75000,
department: "Engineering",
hireDate: new Date("2023-01-01")
})

# Insert multiple documents


db.employees.insertMany([
{
name: "Jane Smith",
position: "Product Manager",
salary: 85000,
department: "Product",
hireDate: new Date("2023-02-15")
},
{
name: "Alice Brown",
position: "UX Designer",
salary: 70000,
department: "Design",
hireDate: new Date("2023-03-10")
}
])
# Check the documents in the collection:
db.employees.find()

# Updating the Data

#Update a specific document (find by condition):

db.employees.updateOne(

{ name: "John Doe" },

{ $set: { position: "Senior Software Engineer", salary: 90000 } }

# Update multiple documents

db.employees.updateMany(

{ department: "Engineering" }, // Condition to find the documents to update

{ $set: { salary: 85000 } } // Set the 'salary' field to 85000 for all matching

documents

)
2)(b). Build a Basic React App that Display “Hello World!”

Ans)

Create a new React project:

npx create-react-app hello-world-app

Navigate to the project folder:

cd hello-world-app

Navigate to src/App.js:

Replace the existing code with a simple component that displays "Hello World!":

# Save and View the Changes

In terminal run the following command:

npm start

3)(b). Write a node.js program to replace strings using Regular Expression.


Ans)

4)(b). Create a REST backend API with Express ?


Ans)
5)(b). Write a MongoDB query to display all the documents in the collection
(Eg. restaurants).

1. First create a database and a collection.


2. Insert few documents in the collection

# 3. Query to Display All Documents in a Collection

db.restaurants.find()

# Or, for a more readable format:

db.restaurants.find().pretty()
6)(b). Create a REST backend API with Express ?

Ans) SAME AS 4 (b)

7)(b). Create database in mongodb and perform insert, update


operations ?

Ans) SAME AS 1 (b)

8)(b). Build a Basic React App that Display “Hello World!”

Ans) SAME AS 2 (b)

9)(b). Write a Node js Program to display “Hello World “?

Ans)

Method 1 :

1. Create a JavaScript File:


Create a new file, hello.js, and add the following code:

console.log("Hello World");

2. Run the Node.js Program in terminal:

node hello.js

This should print "Hello World" to the console.


Method 2:
1 . Create a JavaScript File:
Create a new file, server.js, with the following code:

2. Run the Node.js Program in terminal:

node hello.js

3. Open a web browser and go to http://localhost:3000/.


You should see "Hello World" displayed in the browser.

10)(b). Write a node.js program to replace strings using Regular


Expression.
Ans) SAME AS 3 (b)

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy