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

2
  • 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 Commented May 2, 2018 at 5:43
  • My case is A Commented May 2, 2018 at 15:28

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.