I have an existing collection where I can do some queries on. For further data processing, it would be handy to create some subset collections via query.

I understood that I can use the aggregate function with $match and $expr to e.g. $group some values and at the end use $out to get a new collection with the results.

The thing I am hanging on is not to $group anything, but just put the objects that $match finds into a new collection only. So not the complete objects with all their values. Just the one I am matching. Like when you db[collection].find({$match: {...}}, {"key1": 1, "key2": 0})

Where I get the new matching objects just containing key1: value1 but not key2: value2, which is also in the original collection.

How do I achieve that using aggregate without grouping anything? I read through the documentation and couldn't find any other stage operation that looks good.

1 Answers

1
tom slabbaert On Best Solutions

As i mentioned in the comments $project is the right operator to use to achieve this.