Filtering mongo document using $gte operator under EmployeeDetail collection.
Example:
[{"_id" : ObjectId("60179dd62381fc69d5f1c599"),"Emp_Name" : "Andrew","Emp_Age" : NumberInt(29),"Emp_Salary" : NumberInt(34000),"Emp_Joining_Date" : ISODate("2020-07-03T18:30:00.000+0000")}{"_id" : ObjectId("60179dd62381fc69d5f1c59a"),"Emp_Name" : "Sam","Emp_Age" : NumberInt(34),"Emp_Salary" : NumberInt(34000),"Emp_Joining_Date" : ISODate("2020-07-03T18:30:00.000+0000")}{"_id" : ObjectId("60179dd62381fc69d5f1c59b"),"Emp_Name" : "Rahul","Emp_Age" : NumberInt(54),"Emp_Salary" : NumberInt(34000),"Emp_Joining_Date" : ISODate("2020-07-03T18:30:00.000+0000")}]
Approach
Query: Find employee having age greater than and equal to 34.
db.Employee_Detail.aggregate({$match:{"Emp_Age":{$gte:34}}});
Output:
[{"_id" : ObjectId("60179dd62381fc69d5f1c59a"),"Emp_Name" : "Sam","Emp_Age" : NumberInt(34),"Emp_Salary" : NumberInt(34000),"Emp_Joining_Date" : ISODate("2020-07-03T18:30:00.000+0000")}{"_id" : ObjectId("60179dd62381fc69d5f1c59b"),"Emp_Name" : "Rahul","Emp_Age" : NumberInt(54),"Emp_Salary" : NumberInt(34000),"Emp_Joining_Date" : ISODate("2020-07-03T18:30:00.000+0000")}]
No comments:
Post a Comment