mongoosejs / mongoose-lean-getters

Apply getters on lean() documents: https://mongoosejs.com/docs/tutorials/lean.html
Apache License 2.0
10 stars 15 forks source link

Add support for projected fields #9

Closed tiesch closed 2 years ago

tiesch commented 2 years ago

let's take this document as an example

{
    fisrtname: 'jhon',
    lastname: 'doe',
    email: 'jhondoe@email.com',
    phonenumber: '123',
    password: 'secret',
}

so the idea is to find the document but selecting specific fields (obviously using mongoose-lean-getters)

userCollection.find().select(['fisrtname']).lean({ getters: true });

expected output

{
    fisrtname: 'jhon',
}

received output

{
    fisrtname: 'jhon',
    lastname: undefined,
    email: undefined,
    phonenumber: undefined,
    password: undefined,
}

this behavior is caused by this plugin I tested it with version 0.3.0

query projection reference -> link