Created
January 5, 2023 09:18
-
-
Save Shaxadhere/6ce8336cd6145cdc849ef2bbc8e54d91 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
db.collection.aggregate([ | |
{ | |
"$facet": { | |
"caseByTitle": [ | |
{ | |
"$match": { | |
"caseTitle": { | |
"$regex": ".*godrej.*", | |
"$options": "i" | |
} | |
} | |
} | |
], | |
"caseByCourtName": [ | |
{ | |
"$match": { | |
"caseTitle": { | |
"$regex": ".*madhya.*", | |
"$options": "i" | |
} | |
} | |
} | |
] | |
} | |
}, | |
{ | |
"$addFields": { | |
"tempCases": { | |
"$concatArrays": [ | |
"$caseByTitle", | |
"$caseByCourtName" | |
] | |
} | |
} | |
}, | |
{ | |
$addFields: { | |
cases: { | |
$reduce: { | |
input: "$tempCases", | |
initialValue: [], | |
in: { | |
$concatArrays: [ | |
"$$value", | |
{ | |
$cond: [ | |
{ | |
$in: [ | |
"$$this._id", | |
"$$value._id" | |
] | |
}, | |
[], | |
[ | |
"$$this" | |
] | |
] | |
} | |
] | |
} | |
} | |
} | |
} | |
}, | |
{ | |
"$project": { | |
cases: 1 | |
} | |
} | |
]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment