mongodb+aggregation - delete the upper level in the document
-
I've got a collection of document types:
{fields:{_id:1, f1:10, f2:"репа", f3:200}, computedFields:{id:1}}, {fields:{_id:2, f1:10, f2:"репа", f3:200}, computedFields:{id:2}}, ...
Inside the cadet (pipeline), I need to transform every document into:
{_id:1, f1:10, f2:"репа", f3:200, id:1}, {_id:2, f1:10, f2:"репа", f3:200, id:2}, ...
I mean, we need to get rid of the top level by leaving the bottom.
Please tell me how to do this.
-
Since
fields
have unique identifiers, you can use the method https://docs.mongodb.org/manual/reference/method/db.collection.distinct/#db.collection.distinct :SomeModel.distinct("fields")
This code will return the list. unique facilities
fields
of all collection facilitiesSomeModel
♪ If you need a repetition,distinct
It won't help.