+ 2

Can we create a list using mongoDB aggregation ?

Basically, I am working with mongodb . Data I have is... there is a WaveLength object in that 2 attributes are waveLnId and IntExtInd when IntExtInd =="E" then I need to create externalWlList[] ... with waveLnId for that I need help . Please give me suggestions ..thank you .

9th May 2022, 6:16 AM
NavyaSri
NavyaSri - avatar
2 Respostas
+ 1
Yes, you can create a list using MongoDB aggregation. Here is one way to do it: db.collection.aggregate([ { $match: { IntExtInd: "E" } }, { $group: { _id: null, externalWlList: { $push: "$waveLnId" } } } ]) The first stage of the aggregation pipeline $match filters the documents in the collection based on the condition IntExtInd: "E", so that only the documents with IntExtInd equal to "E" are processed. The second stage of the pipeline $group creates a single document from the filtered documents, grouping the waveLnId values into an array externalWlList. The $push operator adds each waveLnId value to the array. The _id field is set to null to indicate that the grouping should be done across all the filtered documents. This aggregation pipeline will return a single document with a externalWlList field that contains the waveLnId values for the documents with IntExtInd equal to "E".
6th Feb 2023, 12:04 PM
Manhar Hadiyal
Manhar Hadiyal - avatar
0
Manhar Hadiyal Thank you 😊 🙏
11th Feb 2023, 6:58 AM
NavyaSri
NavyaSri - avatar