W
W
wini6662017-11-17 18:38:15
MongoDB
wini666, 2017-11-17 18:38:15

How to display an array of photos and their total number?

How to output this using .aggregate:

{
"count": 3,
"items": [{ }, { }, { }]
}

If I add count it then displays the number, but nothing else
const findImages =  Image.aggregate(
[
{"$count": "count"},
{"$sort": {[sort]: -1}},
{"$skip": parseInt(skip)},
{"$limit": parseInt(limit)},
                {
                    "$project": {
                        "userId": 1,
                        "name": 1,
                        "tag": 1,
                        "count": 1
                    }
                }
]);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
lega, 2017-11-19
@wini666

https://stackoverflow.com/questions/20348093/mongo...
or send 2 queries (might be more efficient)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question