0

Here i want to get AC3 phones list whose price is greater than 200 using aggregation

db.Products.aggregate([{$match:{name:"AC3 Phone"}},{$project:{_id:0,cost:{$price:{$gte:200}}}}]

when i executed above command in mongo shell,this is the error i got

"ok" : 0,
"errmsg" : "Unrecognized expression '$price'",
"code" : 168,
"codeName" : "InvalidPipelineOperator"

My doubt is that can we use $gte operator in projection phase using aggregations in MongoDB as mentioned in above

  • Not clear what you are asking for here. Are you expecting to return **A.** Return **only** phones where the price is greater than 200 **B.** Return ALL phones but indicate if the price is greater than 200 or not. Which one sounds like what you want? **A** or **B** – Neil Lunn May 02 '18 at 05:43
  • My case is **A** – naveen reddy depa May 02 '18 at 15:28

1 Answers1

0

No, You can not use $gte (aggregation operators) with $project, you should check the condition with $match operator.

for further information regarding the aggregation, you can read this link

you can also go through with this answer for your clarification.

Devendra Singh
  • 640
  • 6
  • 12