moleculer-db icon indicating copy to clipboard operation
moleculer-db copied to clipboard

Issue with ObjectId fields

Open avalla opened this issue 6 years ago • 1 comments

Hello,

I have not found any smart issue to manage this problem, the adapter changes the _id field as string, but I have also other ObjectId fields (some references to other collections) and they are not converted to string, so I need to call a toString() for doing other queries, but moleculer validation prevents to call service.getusing an object id or with null values.

My database has some optional references to other entities, so there are null values. I think that is not possible to manage directly, because validator throws an error...

Example

Thanks to everyone :)

[2018-07-10T11:11:26.843Z] INFO  mac-mini-di-andrea.local-20730/TEST: test.save STARTING...
[2018-07-10T11:11:26.853Z] INFO  mac-mini-di-andrea.local-20730/TEST: test.save: { _id: '5b44945e0362e150fa37a60d', _idType: 'string', field: 000000000000000000000001, fieldType: 'object', fieldString: '000000000000000000000001', fieldStringType: 'string' }
[2018-07-10T11:11:26.857Z] INFO  mac-mini-di-andrea.local-20730/TEST: test.save - forcing validation error, using an object for doing: broker.call("test.get", { _id: test.field });
Error occured! Parameters validation error!

avalla avatar Jul 10 '18 11:07 avalla

oh

hienp avatar Mar 04 '20 07:03 hienp