I have this documents:
[ { id: 1 }, {id: 2}, {id: 3} ]
I want to transform that into:
{ ids: [1, 2, 3] }
or
[1, 2, 3]
Which is the most efficient pipeline for that?
Thanks!
I have this documents:
[ { id: 1 }, {id: 2}, {id: 3} ]
I want to transform that into:
{ ids: [1, 2, 3] }
or
[1, 2, 3]
Which is the most efficient pipeline for that?
Thanks!
Copyright © 2021 Jogjafile Inc.
You can use
$groupand$projectstage.For the first result -
{ ids: [1, 2, 3] }, please use the following MongoDB aggregation pipeline.You can get desired result only use
$groupstage in above pipeline, but there is a field_id: null, so you can remove this field using$projectstage.