Julian
Julianβ€’3y ago

Question to the rowy documentation - Doc Snyc

And one more question: For the Doc Sync Extension to work currently the the columns of both documents have to have the same fieldkey (name), ist that corect? Or is there a way to make it work without that in rowy. At the moment I dont see it since there is only one target path and no logic to tell rowy which data should get synchronized to which field.
7 Replies
Julian
Julianβ€’3y ago
const extensionBody: DocSyncBody = async({row, db, change, ref}) => {
return ({
fieldsToSync: ["firstName"],
row: row,
targetPath: `secondaryCollection/${ref.id}`, //
})
}
const extensionBody: DocSyncBody = async({row, db, change, ref}) => {
return ({
fieldsToSync: ["firstName"],
row: row,
targetPath: `secondaryCollection/${ref.id}`, //
})
}
And do I understand this example code correct? In the example, I would synch the firstName field of my current doc to the id field of the current doc? (since ref represents my current doc) It confuses me and I guess I dont understand it correctly since the idea is to snych different docs I guess
Shams
Shamsβ€’3y ago
hi @Julian ,the example you shared is correct, you can change the field names like this
const extensionBody: DocSyncBody = async({row, db, change, ref}) => {
return ({
fieldsToSync: ["givenName"],
row: {givenName:row.firstName},
targetPath: `secondaryCollection/${ref.id}`, //
})
}
const extensionBody: DocSyncBody = async({row, db, change, ref}) => {
return ({
fieldsToSync: ["givenName"],
row: {givenName:row.firstName},
targetPath: `secondaryCollection/${ref.id}`, //
})
}
or just use a task extention
const extensionBody: TaskBody = async({row, db, change, ref}) => {
return
db.doc(`secondaryCollection/${ref.id}`).set({givenName:row.firstName},{merge:true})
}
const extensionBody: TaskBody = async({row, db, change, ref}) => {
return
db.doc(`secondaryCollection/${ref.id}`).set({givenName:row.firstName},{merge:true})
}
Julian
Julianβ€’3y ago
thanks, so I understand correct, that the fieldkey of the doc (where I want to synch data to) has to have the same name/fieldkey? In a example of synchronizing data to a different doc in my database I dont see where I can tell rowy what the (different) name of the column is, where I want to have this data synchronized. Sorry...I guess I just understood it. ---> Givenname represents this in your example, right?
Shams
Shamsβ€’3y ago
yep
Julian
Julianβ€’3y ago
thanks! Maybe I miss a little sleep πŸ˜„ but maybe you can add this to your docs. THis might help it to understand it
Shams
Shamsβ€’3y ago
the row in the returned object doesnt have to be the same, you can modify it however you like I will update the docs
Julian
Julianβ€’3y ago
awesome, thanks! I was a little confused by the comment "a list of string of column names" --> I thought these are the names of the field I would like to snych but I did not think of them as the names of the fields in the doc where I want to send data to. The attribute name "fieldsToSnych" still to confuses me a littel. For me "fieldsToSynchTo" would be more clear. But maybe thats only me (maybe your can add to the comment / a list of string of column names of the target doc in general I think, rather add more comments to your example code to make everything super clear. This wont harm the people who would understand it event without these comment but it might save you questions and helps the people who are still not that familiar with the firestore cloud function and this environment. Thanks either way!!! πŸ™‚