0% found this document useful (0 votes)
7 views

Experiment:2.1: Use Mongoose To Connect Database For Performing CRUD Operations

The document summarizes an experiment conducted by a student named Nidhi Yadav to perform CRUD operations on a MongoDB database using Mongoose. The student connected to a MongoDB database using Mongoose, defined a schema and model. They then demonstrated inserting, reading, updating and deleting data from the collections using the model. The key learning outcomes were about MongoDB and performing CRUD operations.

Uploaded by

deadm2996
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Experiment:2.1: Use Mongoose To Connect Database For Performing CRUD Operations

The document summarizes an experiment conducted by a student named Nidhi Yadav to perform CRUD operations on a MongoDB database using Mongoose. The student connected to a MongoDB database using Mongoose, defined a schema and model. They then demonstrated inserting, reading, updating and deleting data from the collections using the model. The key learning outcomes were about MongoDB and performing CRUD operations.

Uploaded by

deadm2996
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Experiment:2.

Student Name: Nidhi Yadav UID:22MCA20001


Branch: MCA Section/Group: 3(A)
Semester: 3rd semester Date of Performance:15/10/2023
Subject Code: 22CAH-706 (Back End Technologies)

1. Use Mongoose to connect database for performing CRUD operations.

const mongoose = require("mongoose"); const


con=mongoose
.connect("mongodb://127.0.0.1:27017/dev")
.then(() => {
console.log("connected succesfully");
})
.catch((e) => {
console.log("not cnnected", e);
});
const stdSchema = new mongoose.Schema({
Name: String,
UID: String,
Branch: String,});

const Model = mongoose.model("stud", stdSchema);

INSERT DATA:
Model.create([{
Name: "Nidhi Yadav",
UID: "22mca20001",
Branch: "MCA",
},{
Name: "Kashish",
UID: "22mca20021",
Branch: "MCA",
},{
Name: "Deepanshi",
UID: "22mca20501",
Branch: "MCA",
}])
.then((data) => {

mongoose.connection.close();

console.log(data)

})
.catch((e) => {
mongoose.connection.close();
});

inSert();

READ DATA:
const finds = async () => { await con; let

data = await Model.find({Name:'Paul'});

console.log(data);

};
finds();
UPDATE DATA:
const updates = async () => { await con; let data = await

Model.updateOne({Name:'Kashish'},{Branch:'BCA'});

console.log(data);

};

updates();
DELETE DATA:
const Delete = async () => { await con; let data =

await Model.deleteOne({Name:'Paul'});

console.log(data);

};

updates();

LEARNING OUTPUT:
1. Learnt about Mongodb;
2. Learnt about CRUD.

You might also like