it make id field undefined, if I set lean: true
utkarsh27a opened this issue · comments
Description
Either there is an issue with implementation of lean
& leanWithId
, or the docs needs an update
In collection schema I have both fields _id(mongo object id) and id(uuid) with some other fields. I'm using options:
options = { select: { "_id": 0, "__v": 0 }, lean: true };
So it should return all fields(without _id and __v) of the documents,
It's returning all fields but making id(uuid) field undefined.
Below lines are from the docs:
[lean=false] {Boolean} - Should return plain javascript objects instead of Mongoose documents? Documentation
[leanWithId=true] {Boolean} - If lean and leanWithId are true, adds id field with string representation of _id to every document
So according to docs lean: true
should not do any changes, and leanWithId will do.
Also with leanWithId: true
I'm getting my id field with uuid, it does not put string representation of _id in id field, which is good for me and I'm using leanWithId: true
for now.
It's a small bug, you can only modify the docs to solve it, but the implementation does not match the documents, So I'm adding this to inform you if any one else get this issue this will save their time.
@utkarsh27a You are right, as you are not selecting _id - the id field could return undefined. I will add a patch, if you are not selecting _id then while leaning id will be null.
Thanks for pointing this out.