const CampaignSchema = new Schema(
{
name: {
type: String,
required: true
},
userId: {
type: ObjectId,
ref: 'User'
},
liEmail: {
type: String,
required: true
},
type: {
type: String,
enum: campaignConstants.COMPAIGN_TYPES,
default: campaignConstants.CUSTOM
},
sequences: [
{
type: Sequence,
required: true
}
],
excludeOption: {
type: Boolean,
default: false
},
sourceLinks: [String],
data: [
{
targetId: {
type: ObjectId,
ref: 'Target'
},
profileLink: String,
name: String,
headline: String,
imageurl: String,
actions: [Activity]
}
],
browserKey: String
},
{
versionKey: false,
timestamps: true
}
)
I'm going to push ACTIVITY object to the campaign->data->actions. This ACTIVITY object will be coming through request with browserKey. This browserKey and profielLink is for indicating the Campaign. and profileLink to indicate specific object of data array
I tried like this myself but not working
const campaign = await Campaign.findOne({ browserKey })
const data = campaign.data.filter(
e => e.profileLink === target.profileLink
)
data.actions.push(action)
await campaign.save()