moleculerjs / database

Advanced Database Access Service for Moleculer microservices framework
MIT License
32 stars 15 forks source link

CreateEntity doens't handle _id ObjectId #11

Closed l0x539 closed 1 year ago

l0x539 commented 2 years ago

https://github.com/moleculerjs/database/blob/ed33d2dcbacb6d3ac8793e0698e1a9c5e71d008d/src/methods.js#L497

I'm not sure if this issue is related to moleculerjs database or another specific package, but Should createEntity handle converting _id string to ObjectId when passing a string _id (similar to mongoose where you can initialize new ObjectId using mongoose.Types.ObjectId())?

For example in this next image, createEntity with _id as string creates an _id string type instead of an ObjectId type, even with using new ObjectId() from mongodb package.

image

l0x539 commented 2 years ago

https://github.com/moleculerjs/database/blob/ed33d2dcbacb6d3ac8793e0698e1a9c5e71d008d/src/adapters/mongodb.js#L230

For example, the default adapter here handles converting _id, except for insert

devalexandre commented 2 years ago

https://github.com/moleculerjs/database/blob/ed33d2dcbacb6d3ac8793e0698e1a9c5e71d008d/src/methods.js#L497

I'm not sure if this issue is related to moleculerjs database or another specific package, but Should createEntity handle converting _id string to ObjectId when passing a string _id (similar to mongoose where you can initialize new ObjectId using mongoose.Types.ObjectId())?

For example in this next image, createEntity with _id as string creates an _id string type instead of an ObjectId type, even with using new ObjectId() from mongodb package.

image

try use, findById("") , you are usgin two _id in your find too, for use some ids use '_id': { $in: []}

icebob commented 2 years ago

Could you create a repro example?