mongoose-lean-defaults
mongoose-lean-defaults copied to clipboard
[BUG] Wrong projection when a field starts with another field name
Describe the bug
The projection returns unselected fields when they start with another field name.
For instance, if we have the following schema
const schema = new Schema({
myField: String,
myFieldButLonger: String,
});
Then a query like this
Model.find().select({ myField: 1 });
Would return both fields.
To Reproduce
Steps to reproduce the behavior:
- Create a schema with 2 fields with the same prefix
- make a request with the shorter field name selected
Expected behavior
Only have the default value on the selected field and keep other fields as undefined
.
Additional context
Mongoose version: ^6.0.0 Node version: latest