Hello All,
I was running an aggregate, on which I am using the hint operator of Mongodb. But when I ran a query with $hint it took nearly 7.2 seconds, and when I ran the same query with hint, it took nearly 3 seconds.
I am unable to find the reason why it is happening. Can you please let me know what can be the reason or am I executing the query in the wrong manner?
Query:
db.collection_name.aggregate([
{
"$match": {
"field_name": {
//Some Conditions
},
"field_name2": {
// list of object ids to be filtered out
}
},
{
"$sort": {
"name": 1
}
},
{
"$facet": {
"new_createdField": [
{
"$skip": 0
},
{
"$limit": 10
}
],
"totalCount": [
{
"$count": "count"
}
]
}
},
{
"$project": {
"new_createdField": 1,
"totalCount": {
"$arrayElemAt": [
"$totalCount.count",
0
]
}
}
}
],{
$hint: ({
field_name: 1,
field_name2: 1,
name: 1
})
);
The same query is executed with the hint-operator.
Additional Information
field_name, field_name2, and name are already in Compound Index.