Populate does not consider toJSON and id:true #14620
Labels
can't reproduce
Mongoose devs have been unable to reproduce this issue. Close after 14 days of inactivity.
Stale
Prerequisites
Mongoose version
8.4.0
Node.js version
21.7.1
MongoDB server version
7.0.8
Typescript version (if applicable)
No response
Description
I have 2 schema, and 1 was populating another one. and both has id:true and toJSON implemented to delete ret._id;
but not working after 8.4.0 when I switched back to 8.0.3 it is working fine. it created lot of issues since frontend was expecting id but was returning _id.
Steps to Reproduce
Try creating 2 schema and populate one from another, implement id:true and toJSON to remove any fields.
It will work on version 8.0.3 but will not work on 8.4.0
@Schema({ id: true, timestamps: true, toJSON: { virtuals: true, versionKey: false, transform(doc, ret) { delete ret._id; }, } })
PassingInfoSchema.virtual('entry', { ref: 'ParkingEntry', localField: 'entryId', foreignField: '_id', justOne: true, });
Expected Behavior
behavior of populated fields should be same as earlier.
Please look into it.
The text was updated successfully, but these errors were encountered: