'How to populate all value of Schema into newly inserted document of mongodb collection
I'm inserting new document if it's not exist in collection and if it's exist I'm simply updating it. but the problem is, newly created document only populating with default value of Schema, other value of Schema is not there in new document.
Student Schema
const StudentSchema = new mongoose.Schema({
Name:String,
subject:{
type: String
default: ''
},
student_id:Number,
lastName:String,
Address:String
})
const filter = { Name:'xxx' }
const options = { upsert: true, new: true }
const update = { student_id:12 }
const result = await StudentSchema.findOneAndUpdate(filter, update, options)
Result, How to populate lastName and Address field in the newly created document
{
_id: new ObjectId("6220647e6c9ba6e113573535"),
Name: 'xxx',
__v: 0,
student_id:12,
subject:'',
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
