Scenario: From “psorder” collection fetching ‘worNumber’ list along with conditions (Sub Query) and pass that list, with in the same collection and exclude those ‘worNumber’.
How to achieve this in aggregation and Java code . Please guide us to sort out the below query.
Query: db.getCollection(‘psorder’).find({
“personName”:{$exists:false},
“worNumber”:{
$nin: db.getCollection(‘psorder’).distinct(“worNumber”,{“statusId”:“new”,
“personName”:{$exists:true},
“personName”: { $ne: “robert” }})
}
}).limit(1);