1

I have in a collection stores , products and many prices (for store-products there are many prices) of the products in MongoDB I have to find out min price from a product in a store in the last 30 days with the help of go I have built the following aggregation pipeline

pipeline := []bson.M{
        bson.D{
            "$group", bson.D{
                {
                    "_id", bson.D{
                        {
                            Key:   "storeId",
                            Value: "$storeUd",
                        },
                        {
                            Key:   "productId",
                            Value: "$productId",
                        },
                    },
                },
                minPrice : {
                    Key:   "min",
                    Value: "$price",
                },
            },
        }  <---
}

But go compiler tell me in the line that I marked with an arrow (<---) there is a mistake

syntax error: unexpected newline in composite literal; possibly missing comma or }

I would like to calculate something like

select min(price)
from prices
group by storeId , productId

Please can you tell me what is wrong?

Thanks, Aurel


I added }, but what I get you can see in the attached picture - the next declaration (var ... ) is in red .... enter image description here

ChrisF
  • 134,786
  • 31
  • 255
  • 325
user1540471
  • 421
  • 2
  • 5
  • 7
  • You have to add a final comma! `},` See possible duplicate: [How to break a long line of code in Golang?](https://stackoverflow.com/questions/34846848/how-to-break-a-long-line-of-code-in-golang/34848928#34848928) – icza Jan 30 '23 at 15:25

0 Answers0