T
T
teertsneerg2020-07-13 13:57:03
Mongoose
teertsneerg, 2020-07-13 13:57:03

How to group mongoose fields?

There is a collection:

{ "_id": "111", "area": "Omsk", "price": '500', "type:" "meal"}
{ "_id": "222", "area": "Moscow", "price": '500'," type": "meal"}
{ "_id": "333", "area": "Omsk", "price": '500', "type": "meal"}
{ "_id": "444", "area": "Moscow", "price": '500', "type": "meal"}


The output would be something like
{
    "Moscow": 
    {
        { "_id": "222", "price": '500'," type": "meal"},
        { "_id": "444", "price": '500', "type": "meal"}
    },
    "Omsk":
    {
        ...
    },
    ....
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrew Hecc, 2020-07-13
@Hecc

There is an aggregate api through which this can be done.
https://docs.mongodb.com/manual/reference/operator...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question