I am trying to remove duplicate value from array which I am able to successfully achieve with below query however having difficulties skip key where values is null. I am using following code
db.mobile_data.aggregate([{$unwind: '$All_Participants'},
{$group: {_id:'$_id',All_Participants: {$addToSet: '$All_Participants'},
Chat_group: {$first: '$Chat_group'}, Message_id: {$first: '$Message_id'} }}]);
my output result as follow
{
"_id" : ObjectId("5856b1e39a47e6d13dab370b"),
"All_Participants" : [
"user1",
"user4"
],
"Chat_group" : 67.0,
"Message_id" : Null
}
How can ignore Message_id
if value is null? Expected output should be
{
"_id" : ObjectId("5856b1e39a47e6d13dab370b"),
"All_Participants" : [
"user1",
"user4"
],
"Chat_group" : 67.0
}