Details
-
Task
-
Resolution: Won't Do
-
Major - P3
-
None
-
3.6.14
-
None
-
Windows
Description
Description
I noticed that using $facet with large amount of data is a lot slow than making multiple calls to database. In my example, my collection has 160000 records, 56000 is ChannelCode "dtm".
Using $facet it takes 600ms to complete:
db.getCollection('application_view').aggregate(
[
{
"$match":
},
{
"$facet": {
"results": [
{ "$sort":
},
,
{ "$limit": 10 } ],
"total": [
]
}
}
]
)
Making 2 calls to db takes 600ms too, but when I add an index
{StatusCode: 1, ApplicationDate: 1}it decreases to 54ms, but the example with $facet continues the same:
db.getCollection('application_view').aggregate([
{$match: {"ChannelCode": "dtm"}},
{$sort: {ApplicationDate: 1}},
{$skip: 0},
{$limit: 10}
])
db.getCollection('application_view').aggregate([
{$match: {"ChannelCode": "dtm"}},
{$count: "count"}
])
Why this is happening? How can I improve the time with $facet?
Thanks in advance.