How to make mongo aggregation outcome persist

below is my my mongo aggregation pipeline

[{
 $match: {
  email: {
   $ne: null
  },
  current_landing: 'DASHBOARD'
 }
}, {
 $lookup: {
  from: 'profile_recommendation_info',
  localField: '_id',
  foreignField: 'profile_id',
  as: 'result'
 }
}, {
 $sort: {
  'result.created_date': 1
 }
}, {
 $addFields: {
  oldest_profile_recommendation_info_data: {
   $arrayElemAt: [
    '$result',
    0
   ]
  }
 }
}, {
 $set: {
  oldest_profile_recommendation_info_id: '$oldest_profile_recommendation_info_data._id'
 }
}, {
 $unset: 'oldest_profile_recommendation_info_data'
}]

As seen in aove pipeline i am setting oldest_profile_recommendation_info_id with some values.I want to persist them in my data.But unable to do so

Have a look at the $out and $merge pipeline stages. Both of these will allow you to save the results from your aggregation command.

3 Likes

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.