I am using the $project stage in an aggregation pipeline using Pymongo on AWS DocumentDB, like so:
{ '$project': { 'foo': 0 } }
This results in the following error:
$projection requires at least one output field
As far as I can tell, the mongo docs state that as of Mongo version 3.4 you can use $project to specify exclusions of fields (see: https://www.mongodb.com/docs/v4.0/reference/operator/aggregation/project/). The example they provide looks like:
db.books.aggregate( [ { $project : { "lastModified": 0 } } ] )
Does docdb not match this part of the API spec? or am I missing something?
EDIT: I'm also unable to use the _id filter specifically, which is also highlighted in mongo docs.
{'$project': {'_id': 0}}
Excluding just _id is not currently supported, i.e. { '$project': { '_id': 0 } }
But, projecting a non existing field can enforce exclusion: { '$project': { '_id': 0, 'foo_field': 0 } }