+ 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 .
2 Antworten
+ 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".
0
Manhar Hadiyal Thank you 😊 🙏