Hi, everybody. I have some issues about init data
Now y-leveldata is supporting that store and fetch ydoc object into leveldb
But I need to fetch init data from table’s field value. So I build self persistence module using ytext.insert(0, value).
getYDoc (ydoc, docName) {
return this._transact(async db => {
const document = await getMongoData(db, info)
for (let key in document) {
const value = document[key]
if (typeof value === ‘string’ || value instanceof String) {
//. insert data
let yTextName = {genereate by collection, document_id and name}
ydoc.getText(yTextName).insert(0, value)
}
}
})
}
This is my persistence module’s getYDoc function.
And I added setPersistence in server.js
utils.setPersistence({
bindState: async(docName, ydoc, a, b) => {
await ldb.getYDoc(ydoc, docName);
},
writeState: async (docName, ydoc) => {}
})
When the user load page, it will be work well at first time. But if server restart or client reconnect, it will be duplicate data
I thought that this case will retry bindState in server sider. because clients has been closed
So I am not sure how to fix this issue.
Thanks.