[DOCS-7789] Comment on: "manual/reference/operator/aggregation/filter.txt" Created: 02/May/16  Updated: 03/Nov/17  Resolved: 02/May/16

Status: Closed
Project: Documentation
Component/s: None
Affects Version/s: None
Fix Version/s: 01112017-cleanup

Type: Bug Priority: Major - P3
Reporter: Docs Collector User (Inactive) Assignee: Unassigned
Resolution: Cannot Reproduce Votes: 0
Labels: collector-298ba4e7
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Location: https://docs.mongodb.org/manual/reference/operator/aggregation/filter/
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Safari/537.36
Referrer: https://www.google.com/
Screen Resolution: 1920 x 1080


Participants:
Days since reply: 7 years, 41 weeks, 2 days ago

 Description   

I tried this exact example and I'm getting the following error:

2016-05-02T10:42:40.553-0700 E QUERY Error: command failed:

{ "errmsg" : "exception: invalid operator '$filter'", "code" : 15999, "ok" : 0 }

: aggregate failed
at Error (<anonymous>)
at doassert (src/mongo/shell/assert.js:11:14)
at Function.assert.commandWorked (src/mongo/shell/assert.js:254:5)
at DBCollection.aggregate (src/mongo/shell/collection.js:1278:12)
at (shell):1:8 at src/mongo/shell/assert.js:13



 Comments   
Comment by Ravind Kumar (Inactive) [ 02/May/16 ]

Tested as working in MongoDB 3.2. Note that $filter is not available for version of MongoDB prior to 3.2.0

> db.foo.find().pretty()
{
	"_id" : 0,
	"items" : [
		{
			"item_id" : 43,
			"quantity" : 2,
			"price" : 10
		},
		{
			"item_id" : 2,
			"quantity" : 1,
			"price" : 240
		}
	]
}
{
	"_id" : 1,
	"items" : [
		{
			"item_id" : 23,
			"quantity" : 3,
			"price" : 110
		},
		{
			"item_id" : 103,
			"quantity" : 4,
			"price" : 5
		},
		{
			"item_id" : 38,
			"quantity" : 1,
			"price" : 300
		}
	]
}
{
	"_id" : 2,
	"items" : [
		{
			"item_id" : 4,
			"quantity" : 1,
			"price" : 23
		}
	]
}
> 
> 
> db.foo.aggregate([
...    {
...       $project: {
...          items: {
...             $filter: {
...                input: "$items",
...                as: "item",
...                cond: { $gte: [ "$$item.price", 100 ] }
...             }
...          }
...       }
...    }
... ])
{ "_id" : 0, "items" : [ { "item_id" : 2, "quantity" : 1, "price" : 240 } ] }
{ "_id" : 1, "items" : [ { "item_id" : 23, "quantity" : 3, "price" : 110 }, { "item_id" : 38, "quantity" : 1, "price" : 300 } ] }
{ "_id" : 2, "items" : [ ] }

Generated at Thu Feb 08 07:55:01 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.