I have a list of fields I would like to exclude in my mongo projection. Using the exclude() method in mongo projection, I was able to retrieve data with the specified values excluded.
// My list of fields to exclude
val fieldList = List("Date", "People")
// the projection
val excludeStuff: Bson = Projections.exclude(fieldList.asJava)
However, now I want to only exclude the “Name” field for the “People” array field:
e.g.
"Type" : "Green",
"Date" : "2022-10-21",
"People" : [{
"RSVP": "Yes",
"Name": "Peter"
},
{
"RSVP": "No",
"Name": "Pan"
},
]
will become:
{
"Type" : "Green"
}
but I need:
"Type" : "Green",
"People" : [{
"RSVP": "Yes"
},
{
"RSVP": "No"
}
]
Any ideas? Thank you!
I have tried this post: Mongo how to exclude nested _id in the nested array
but I need the projection specifications to be in a list, so how can I do something like:
val fieldList = List("Date", "People.Name???")