Hello everybody. Let’s say I have this model:
const userSchema = new Schema({
email: {
type: String,
required: true,
unique: true
},
firstname: String,
lastname: String,
password: {
type: String,
required: true
},
activities: [{
description: {
type: String,
required: true
},
status: String,
from: Date,
to: Date
}]
}, { timestamps: true })
After I get the user with User.findById()
, how can I get the ObjectId
of an activity inside the activities
array so I can perform (for example) delete
and update
operations? I can see every ObjectId with console.log()
or in Atlas because MongoDB creates an ObjectId for every element inside the array even if I don’t specify the field _id
for each element.