Sample Data Uploaded
{"_id":{"$oid":"63da91711b5a61ae22f2fdf1"},"title":"Tu raj kare","artist":"Jaago Music","tempo":{"$numberInt":"68"},"link":"https://www.youtube.com/watch?v=6M844pWC31M","__v":{"$numberInt":"0"}}
the last value of __v":{"$numberInt":"0"} shouldn't be there
Here is the model I am using
const mongoose = require('mongoose');
const songSchema = new mongoose.Schema({
title: String,
artist: String ,
tempo: Number,
link: String,
});
const Song = mongoose.model('songs', songSchema);
module.exports = Song;
This is the router code I am using to upload the data to MongoDB
router.post('/upload', async (req, res) => {
const { title, artist, tempo, link } = req.body;
if (!title || !link) {
return res.status(422).json({ error: "Please fill all the fields" });
}
try {
//FINDS IF THE SONG ALREADY EXISTS IN THE DATABASE
const songExists = await Song.findOne({ title: title });
if(songExists) {
return res.status(422).json({ error: "Song already exists" });
}
//SAVES THE SONG TO THE DATABASE
const song = new Song({title, artist, tempo, link});
await song.save()
res.status(201).json({ message: "Song uploaded successfully" });
} catch (error) {
console.error(error);
}
});
I am just trying to upload Song details which contains title , artist, tempo, link.
The things getting shown in my MongoDB Atlas Collection is title , artist, tempo, link & --v
--v is unnecessary