When i use findById, replaceById or updateById of legacy-juggler with mongodb, an unwanted id field is added to every nested object
Steps to reproduce
//the model
export class NestedDoc extends Model{
@Property() myProp1?: string;
@Property() myProp2?: number;
}
export class MyEntity extends Entity {
@Property({
type: 'string',
id: true,
})
id: string;
@Property({
type: 'string',
required: true,
})
name: string;
@Property() nested?: NestedDoc;
}
//in the controller
await this.MyEntityRepository.replaceById( myEntity.id, myEntity );
Current Behavior
after the update/replace, the result in the db is
{
"_id": {
"$oid": "5f228e05ae69644ed8f31445"
},
"name": "entityname",
"nested": {
"id": null,
"myProp1": "prop1",
"myProp2": 2
}
}
Expected Behavior:
do not add "id" fields to nested objects
Additional information:
When replacing document a warning appear in console:
WARNING: id property cannot be changed from 5f228e05ae69644ed8f31445 to 5f228e05ae69644ed8f31445 for model:MyEntity in 'loaded' operation hook
*edit. THIS ALSO HAPPEN WITH updateById
*edit. also findById returns undefined id for nested objects, also if in the db that field does not exists
versions:
win32 x64 13.10.1
+-- @loopback/authorization@0.6.2
+-- @loopback/boot@2.3.5
+-- @loopback/context@3.9.2
+-- @loopback/core@2.9.1
+-- @loopback/express@1.2.5
+-- @loopback/http-server@2.1.9
+-- @loopback/openapi-v3@3.4.5
+-- @loopback/repository@2.9.0
+-- @loopback/security@0.2.14
+-- @loopback/service-proxy@2.3.4
+-- loopback-connector-mongodb@5.2.2
*EDIT After many test i see that the issue is only on the findById that returns that non-existent id fields. The corrupt data was then saved to db in other parts of the code that I had not seen