Skip to Main Content

MongoByte MongoDB Logo

Welcome to the new MongoDB Feedback Portal!

{Improvement: "Your idea"}
We’ve upgraded our system to better capture and act on your feedback.
Your feedback is meaningful and helps us build better products.

Status Submitted
Categories Database
Created by Guest
Created on Sep 9, 2022

Allow Dynamic Object In $project and $addFields

Assume I have a field mapping defined in some configuration collection of my application. And this field mapping varies for different clients on my application. I would like to pass the dynamic object in my $project or $addFields stage Like: $project: { {$arrayToObject: "$field_mapping"}, } {$arrayToObject: "$field_mapping"} would return something like "email" : "$data.Email", "phone" : "$data.Phone, "first_name" : "$data.FirstName", "last_name" : "$data.LastName", "preferred_channel" : "$data.Channel", "preferred_language" : "$data.LanguageCode", "email_channel" : "$data.Email", "sms_channel" : "$data.SMS", "province" : "$data.CustomerState"
  • Attach files