const mongoose = require('mongoose');
mongoose.connect("mongodb://localhost:27017/newDB", { useNewUrlParser: true })
.then(() => {
console.log("connction successful...")
})
.catch((err) => console.log(err));
const playlistSchema = new mongoose.Schema({
// define schema
name: {
type: String,
required: true
},
sirname: String,
email: String,
role: String,
active: Boolean,
date: {
type: Date,
default: Date.now
},
roll: Number,
})
// collection creation
// in model("collection name", define schema)
const PlayList = new mongoose.model("PlayList", playlistSchema)
// Update the document
const updateDocument= async(_id)=>{
try{
const result = await PlayList.updateOne({_id},
{$set : {role : "Block-Chain"}}
);
console.log(result)
}catch(err){
console.log(err)
}
}
updateDocument("61cc0946c62a51adf6bc23db")
connction successful...
{
acknowledged: true,
modifiedCount: 1,
upsertedId: null,
upsertedCount: 0,
matchedCount: 1
}
Post a Comment