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

Casting for top-level $expr #10663

Closed
vkarpov15 opened this issue Sep 2, 2021 · 0 comments
Closed

Casting for top-level $expr #10663

vkarpov15 opened this issue Sep 2, 2021 · 0 comments
Labels
discussion If you have any thoughts or comments on this issue, please share them! enhancement This issue is a user-facing general improvement that doesn't fix a bug or add a new feature
Milestone

Comments

@vkarpov15
Copy link
Collaborator

Do you want to request a feature or report a bug?

Feature

What is the current behavior?

Re: #10622, right now we don't do any casting on $expr. And sanitizeFilter doesn't do anything with $expr either.

If the current behavior is a bug, please provide the steps to reproduce.

const mongoose = require('mongoose');
mongoose.set('debug', true)
const testSchema = new mongoose.Schema({ date: {type: Date, required: true }}, {timestamps: {createdAt: 'created_at', updatedAt: 'updated_at'}})

testSchema.index({ date: -1});

const Test = mongoose.model('Test', testSchema);

async function test() {
    await mongoose.connect('mongodb://localhost:27017/test', {
        useNewUrlParser: true,
        useUnifiedTopology: true,
      });
      await mongoose.connection.dropDatabase();

      await Test.find( { $expr: { $eq: [{ $year: '$date' }, 2021] } }, {date: 1}).sort({ date: -1 });
      console.log('Done');
}

test();

What is the expected behavior?

Not sure yet, but something we need to figure out. Questions:

  1. Should sanitizeFilter() remove $expr?

  2. How much casting can we reasonably do on $expr? In the above example, can we figure out that 2021 needs to be a number?

What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.

@vkarpov15 vkarpov15 added enhancement This issue is a user-facing general improvement that doesn't fix a bug or add a new feature discussion If you have any thoughts or comments on this issue, please share them! labels Sep 2, 2021
@vkarpov15 vkarpov15 added this to the 6.1.0 milestone Sep 2, 2021
@vkarpov15 vkarpov15 modified the milestones: 6.1.0, 6.2.0 Nov 17, 2021
vkarpov15 added a commit that referenced this issue Jan 27, 2022
Casting for `$expr` in queries
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion If you have any thoughts or comments on this issue, please share them! enhancement This issue is a user-facing general improvement that doesn't fix a bug or add a new feature
Projects
None yet
Development

No branches or pull requests

1 participant