FirestoreGoogleAppsScript icon indicating copy to clipboard operation
FirestoreGoogleAppsScript copied to clipboard

Unable to update nested fields with custome mask in updateDocument()

Open zhezhang77 opened this issue 3 years ago • 0 comments

The custom mask is interpreted as a whole field name instead of the nested field name. Therefore there is no way to update a nested field with it.

Minimal code to reproduce the problem

const firestore = FirestoreApp.getFirestore(email, key, projected);

const original = {
    field1: 'value1',
    field2: 'value2',
  
    field3: {
        field4: 'value4',
        field5: 'value5',
    },

    'field3.field4': 'value3.4',
}

const update = {    
    field3: {
        field4: 'new value4',
    },
    'field3.field4': 'new value3.4',
}

firestore.createDocument('TestCol/TestDoc', original);
var updated = firestore.updateDocument('TestCol/TestDoc', update, ['field3.field4']);

Expected Behavior

updated = {
    field1: 'value1',
    field2: 'value2',
    
    field3: {
        field4: 'new value4',  //<-- Updated
        field5: 'value5',
    }

    'field3.field4': 'value3.4',
}

Actual Results

updated = {
    field1: 'value1',
    field2: 'value2',
    
    field3: {
        field4: 'value4',
        field5: 'value5',
    }

    'field3.field4': 'new value3.4',  //<-- Updated
}
Library Version: Head

zhezhang77 avatar Nov 09 '22 23:11 zhezhang77