Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't match a ISODate range #47

Open
Gabrirf opened this issue Sep 26, 2022 · 1 comment
Open

Can't match a ISODate range #47

Gabrirf opened this issue Sep 26, 2022 · 1 comment

Comments

@Gabrirf
Copy link

Gabrirf commented Sep 26, 2022

I have my documents created with createdAt and updatedAt fields from mongoose feature. I normally add date filters in this way:

const filters = {};
if (from) filters.createdAt = { $gte: new Date(from).toISOString() };
if (to) filters.createdAt = { $lte: new Date(to).toISOString() };
if (from && to) {
  filters.createdAt = {
    $gte: new Date(from).toISOString(),
    $lte: new Date(to).toISOString(),
  };
}

For the aggregate I use:

const options = {};
const filtersPipeline = {
    $match: {
      ...filters,
    },
  };
const aggregateQuery = MyModel.aggregate([
    filtersPipeline,
]);
MyModel.aggregatePaginate(aggregateQuery, { ...options, ...paginationOptions });

It should filter from-to date, but I got an empty array on results

I'm using Node v14 with:

{
    "mongoose": "5.12.9",
    "mongoose-aggregate-paginate-v2": "1.0.42",
    "mongoose-paginate-v2": "1.3.14"
}

This query it's working directly on Robo3t:

db.getCollection('mymodel').aggregate([
    { $match: {
        createdAt: { $gte: ISODate('2022-09-16T09:45:17.000Z') },
    }}
])
@dev-stupid-codes
Copy link

I can't even match by _id

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants