rxDB incrementalPatch when there is an object

87 views Asked by At

I am using rxDB like this to update my document:

await doc.incrementalPatch({
    ...newDoc,
    updated_at: new Date().toUTCString(),
});

However I get this issue:

RxError (DOC6):
RxDocument.populate() cannot populate because path has no ref
Given parameters: {
path:"location.latitude"
schemaObj:{
  "type": "number"
}}
RxError (DOC6): RxError (DOC6):
RxDocument.populate() cannot populate because path has no ref
Given parameters: {
path:"location.latitude"
schemaObj:{
  "type": "number"
}}

the location property is defined as follows:

location: {
      type: 'object',
      properties: {
        altitude: {
          type: 'number',
        },
        latitude: {
          type: 'number',
        },
        longitude: {
          type: 'number',
        },
      },
    },

Now this issue only occurs when location is not undefined. When its set I get this issue. Any ideas how to solve this?

1

There are 1 answers

0
strangeQuirks On

I only found this solution:

const updatedDoc = {
        ...doc,
        updated_at: new Date().toUTCString(),
      };

      if (updatedDoc.location && doc.location) {
        updatedDoc.location = {};
        updatedDoc.location.latitude = doc.location.latitude;
        updatedDoc.location.longitude = doc.location.longitude;
        updatedDoc.location.altitude = doc.location.altitude;
      }

      await dumpDoc.incrementalPatch(updatedDoc);

Not the best so if anyone comes across this and knows something better please let me know :)