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

Make strictQuery false by default again #11861

Closed
2 tasks done
vkarpov15 opened this issue May 31, 2022 · 6 comments
Closed
2 tasks done

Make strictQuery false by default again #11861

vkarpov15 opened this issue May 31, 2022 · 6 comments

Comments

@vkarpov15
Copy link
Collaborator

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Mongoose version

6.x

Node.js version

Any

MongoDB server version

Any

Description

The strictQuery change in Mongoose 6 (https://mongoosejs.com/docs/migrating_to_6.html#strictquery-is-removed-and-replaced-by-strict) has caused a lot of confusion. Here's a couple:

#11609
#11807
#11514

Etc.

Steps to Reproduce

From #11609:

const mongoose = require('mongoose');

const testSchema = new mongoose.Schema({
    title: [{
        value: String,
        language: String
    }]
});

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

async function run() {
    await mongoose.connect('mongodb://localhost:27017');
    await mongoose.connection.dropDatabase();

    await Test.create({
        title: [{
            value: 'El Dave valencia',
            language: 'ca'
        }, {
            value: 'El Dave castellano',
            language: 'es'
        }]
    });

    await Test.create({
        title: [{
            value: 'test',
            language: 'ca'
        }, {
            value: 'test',
            language: 'es'
        }]
    });

    const query = await Test.find({$or: [{"title.value":/Dave/i},{"name.value":/Dave/i} ]});
    console.log('done', query, query[0].title, query[1].title);
    
}

run();

Expected Behavior

Make strictQuery false by default in Mongoose 7

@hasezoey
Copy link
Collaborator

hasezoey commented Sep 20, 2022

as mentioned in #12389 (comment), what about setting it to throw (or return some kind of validation errors like .validate) instead of reverting to false instead of the current "silently remove things" or going back to include "as is"?

@vkarpov15
Copy link
Collaborator Author

@hasezoey 'strictQuery: throw' by default would be a bit too strict to be a default for Mongoose. Wouldn't fit in well with the rest of our defaults.

@vkarpov15
Copy link
Collaborator Author

We should also decouple strict and strictQuery again. Setting strictQuery to strict by default was a workaround, setting strict: false in your schema shouldn't disable strictQuery.

@ilovepixelart
Copy link

@vkarpov15 Glad it will be over soon, can't wait for mongoose 7

SurfaceS added a commit to SurfaceS/api that referenced this issue Dec 14, 2022
(see Automattic/mongoose#11861)

set MovieDb baseUrl to undefined as null is a value
SubJunk pushed a commit to UniversalMediaServer/api that referenced this issue Dec 15, 2022
* test mocks

* test mocks

* test mocks

* test mocks

* test mocks

* test mocks

* upd deps

* upd dev deps

* lint

* upd yarn

* try downgrade mongoose

* updated omdb replies

* updated omdb replies

* updated omdb replies

* updated omdb replies

* updated omdb replies

* log debug

* log more

* added first tmdb mocks

* remove logs
remove tmdb mocks
added get series IMDbID from tmdb as omdb seems to give wrong value

* set local tmdb

* set local tmdb

* set local tmdb

* set local tmdb

* set local tmdb

* omdb-mocks

* update deps

* remove comment

* lint

* remove log

* mongoose strictQuery now default to false

* mongoose strictQuery true to throw
(see Automattic/mongoose#11861)

set MovieDb baseUrl to undefined as null is a value

* clean omdb mocks

* added omdb mocks saison 2

* added omdb mocks saison 3
vkarpov15 added a commit that referenced this issue Jan 17, 2023
BREAKING CHANGE: make strictQuery false by default again
@zhi-qiu-yi
Copy link

why not merge on v6.x? moving to v7.x takes more problem. @vkarpov15

@hasezoey
Copy link
Collaborator

this is a breaking change and so could only be done on a major version change, if you want to disable it globally for 6.x you can use mongoose.set('strictQuery', false) before using any query (like before / after creating the connection)

@Automattic Automattic locked and limited conversation to collaborators Aug 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants