mongodb aggregation with $project to conditionally exclude a field
问题 I would like to exclude a field from a mongo db aggergtion pipeline, after reading the docs, I thought I needed to specify either 1 or 0 to keep the field or not (cf. http://docs.mongodb.org/manual/reference/operator/aggregation/project/) So I tried the following (using node.js mongoose, but the syntax is quite the same as plain mongo): aggregate.match({ date: { $gte : today } }); aggregate.sort('-date'); aggregate.group({ _id: '$name', date: { $first: '$date' }, user: { $first: '$user' },