feat[core]: partially update embedded object properties #1181
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I've added in some logic for when an embedded property is set as { object: true }.
Currently an old query that was:
[query] db.getCollection('user').updateMany({ _id: ObjectId('5fcf95d54f6a9653930f3c8b') }, { '$set': { address1_city: 'new city', address4: { street: null, postalCode: null, city: 'new city 4', country: null } } }, { session: undefined }); [took 2 ms]
now, looks like:
[query] db.getCollection('user').updateMany({ _id: ObjectId('5fcf96cd2c05055470c9edff') }, { '$set': { address1_city: 'new city', address4: { city: 'new city 4' } } }, { session: undefined }); [took 2 ms]
So the changes are computed properly for object types, but I'm not sure where to go from now. I'd have to tap into each specific driver and make sure that for embedded objects on update it doesnt replace the value. Any pointers / ideas?
Is this a good place to do so for mongo?
mikro-orm/packages/mongodb/src/MongoDriver.ts
Line 190 in f3beb7f