rxdb:迁移文档失败的最终文档与最终架构不匹配 类型信息迁移者代码解决方案:

问题描述

我刚刚将我的rxdb模式版本从0更改为1,以便添加deletedAt属性。我添加了从版本0到版本1的迁移策略。

现在我遇到此错误:“文档迁移失败的最终文档与最终架构不匹配”。最终文档在以下屏幕快照中:

console error from react app using rxdb

我认为也许我必须添加_rev字段;在架构中添加_rev并不能消除错误,因此我将其撤回了。与deleted字段同上(抱怨我不能将其添加为顶级属性)。因此,我不知为何最终对象与预期架构不同?

类型信息

export type TodoType = {
  id: string
  text: string
  isCompleted: boolean
  createdAt: string
  updatedAt: string
  deletedAt: string
}
//...
export const todoSchema: RxJsonSchema<TodoType> = {
  title: 'todo schema',description: 'todo schema',version: 1,// just changed this from 0 to 1
  type: 'object',properties: {
    id: {
      type: 'string',primary: true
    },text: {
      type: 'string'
    },isCompleted: {
      type: 'boolean'
    },createdAt: {
      type: 'string',format: 'date-time',// index: true,},updatedAt: {
      type: 'string',format: 'date-time'
    },deletedAt: {
      type: 'string',required: ['id','text','isCompleted','createdAt','updatedAt','deletedAt'],indexes: ['createdAt']
}

迁移者代码

  await myDatabase.collection({
    name: 'todos',schema: todoSchema,methods: todoMethods,statics: todoCollectionMethods,migrationStrategies: {
      // 1 means,this transforms data from version 0 to version 1
      1: function(oldDoc: TodoDocument) {
        oldDoc.updatedAt = oldDoc.updatedAt === '' ? oldDoc.createdAt : oldDoc.updatedAt
        oldDoc.deletedAt = oldDoc.deleted ? oldDoc.updatedAt : ''
        return oldDoc;
      }
    }
  })

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)