I got stuck at this mongoose code. I tried billions of time for this. but in my node app.js output is : MongooseError: document must have an _id before saving at D:\node_modules\mongoose\lib\model.js:297:18 at processTicksAndRejections (node:internal/process/task_queues:78:11)
and also data didn't save on mongoose shell. on some my research on internet i found one answer that if you dont provide '_id' then mongoose will do it automatically. On my code I didn't provide any _id. Now this didnt work also. If i tried with provide _id this also didnt work. What should I do now? Please, save my life!!!
Here is my code:
const mongoose = require('mongoose');
mongoose.connect("mongodb://localhost:27017/newDB", {useNewUrlParser: true});
const peopleSchema = new mongoose.Schema({
name: String,
age: Number,
address: String
});
const People= mongoose.model("People", peopleSchema);
const person = new People(
{
name: "john",
age: 25,
address: "New York, USA"
},
{
name: "Don",
age: 30,
address: "Chicago, USA"
},
{
name: "Kahn",
age: 34,
address: "Dhaka, Bangladesh"
}
);
person.save();