Skip to content

Non-issue regarding lowercase attribute in schema declaration and queries #4569

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

Closed
daretodave opened this issue Sep 27, 2016 · 2 comments
Closed
Milestone

Comments

@daretodave
Copy link

daretodave commented Sep 27, 2016

When a property is specified to be lower cased in the schema -

...   = new Schema({
  username: {type: String, lowercase: true}
})

Shouldn't the select statements that filter on this property lower-case the input?

                User.findOne({
                    username: "DAVID"
                },

VS. doing this before hand?

                User.findOne({
                    username: username.toLowerCase()
                }

The former find seems more practical when the schema denotes the property is lower-cased.

Additionally insert has this behavior of automatically lower-casing the property.

@vkarpov15
Copy link
Collaborator

That's a good suggestion, currently mongoose does not support that but I'd love to add it for a future release

@vkarpov15
Copy link
Collaborator

4.10.0 has an option called runSettersOnQuery, for example:

var testSchema = new Schema({
  name: { type: String, lowercase: true },
  num: { type: Number, set: function(v) { return Math.floor(v); } }
}, { runSettersOnQuery: true });

That will run setters when you're querying

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