To execute queries doing analysis using aggregate and find similar records, $push is used. But, it gives error on certain MongoDB version i.e. 4.2.3.
For example, to execute query “Find Employees with the highest salary”, I have used $push in aggregate functions and allowDiskUse (code mentioned below). But, it shows an error in MongoDB version 4.2.3. " $push used too much memory and cannot spill to disk" .
What is an alternate options other than application-level join?
resultE=db.emp.aggregate([
{ "$group":{
"_id":None ,
"maxSalary": { "$max": "$salary" },
"empgrp": { "$push": {
"_id": "$_id",
"name": "$emp_name",
"sal": "$salary"
}}
}},
{ "$project": {
"maxSalary": 1,
"emps": {
"$setDifference": [
{ "$map": {
"input": "$empgrp",
"as": "emp",
"in": {
"$cond": [
{ "$eq": [ "$maxSalary", "$$emp.sal" ] },
"$$emp",
False
]
}
}},
[False]
]
}
}} ]
, allowDiskUse=True
)