Hello all, I’m trying out different Atlas search options using the aggregate api. The text search has been working great and now i’ve started querying my date fields. The range
operator seems to function as I expect but the near
one doesn’t seem to make a difference in my results.
I’m using the Node driver, and my collection documents are stored as the Date type.
An aggregate pipeline I’m trying:
[
{
$search: {
compound: {
must: [
{
text: {
query: ['shopping'],
path: 'tags',
},
},
{
near: {
path: 'savedAt',
origin: new Date(2022, 0, 1),
pivot: 2629800000,
},
},
],
},
},
},
];
My understanding is that this query will look for documents with “shopping” in their tag field, and that have a savedAt date within ~1 month of January 1st, 2022. I have 19 documents that have shopping
in their “tags” field. Only one of them has a saved at date in 2022 (Jan 5th). My aggregate result however returns all 19 documents.
What am I missing? I would only expect 1 result since a month before and after Jan 1 2022 should only result in the 1 document present? Using the range
operator and defining a “greater than” date of new Date(2022, 0, 1)
returns just that one document.