Let’s say I have a collection like so:
{
"id": "2902-48239-42389-83294",
"data": {
"location": [
{
"country": "Italy",
"city": "Rome"
}
],
"time": [
{
"timestamp": "1626298659",
"data":"2020-12-24 09:42:30"
}
],
"details": [
{
"timestamp": "1626298659",
"data": {
"domain": "example.com",
"name": "John Doe",
"email": "john@doe.com"
},
"type": "client"
},
{ "timestamp": "1626298652",
"data": {
"domain": "example.com",
"name": "John Doe",
"email": "doe@john.com"
},
"type": "employee"
}, {
"timestamp": "1626298652",
"data": {
"domain": "example.com",
"name": "John Doe",
"email": "doe@johnson.com"
},
"type": "client"
},
{ "timestamp": "1626298642",
"data": {
"domain": "example.com",
"name": "John Doe",
"email": "doe@john.com"
},
"type": "employee"
}
]
}
}
And I created indexes as follow:
Text Index:
data.details.data.domain_text_data.details.data.email_text
Regular Index:
data.details.data.domain_1_data.details.data.email_1
Regular Index:
data.details.data.domain_1
All of my queries are using this aggregation pipeline:
await docs.aggregate([
{
$match: {
$and: [
{ "data.details.data.domain": domain },
{ "data.details.type": "employee" },
],
},
},
{
$project: {
id: 1,
"data.time": 1,
"data.location": 1,
details: {
$filter: {
input: "$data.details",
as: "i",
cond: {
$and: [
{ $eq: ["$$i.data.login", domain] },
{ $eq: ["$$i.type", "employee"] },
],
},
},
},
},
},
{
$redact: {
$cond: {
if: { $eq: ["$details", []] },
then: "$$PRUNE",
else: "$$DESCEND",
},
},
},
{ $limit: 500 },
])
domain here is a variable coming from the FE.
My collection has approx 20GB of data and from some reason when I query for “example.com” I can get thousands of docs in 2 seconds, but when I query for “myexample.com” I can get only 2 results in 30 seconds or even more…
Anyone have any idea why it could be happening?