【问题标题】:RxDB - can't find collection after reloadRxDB - 重新加载后找不到集合
【发布时间】:2019-08-13 15:15:16
【问题描述】:

尝试在我的 Angular 应用程序中使用 RxDB。想要一些简单的工作:

export const LANG = {
version: 0,
title: "Language Key",
type: "object",
properties: {
    key: {
        type: "string",
        primary: true
    }
},
required: ["key"]};

RxDB.create({
        name: "test",
        adapter: "idb",
        multiInstance: false
    }).then((db) => {
        if (!db["language"]) {
            db.collection({
                name: "language",
                schema: LANG
            }).then((c) => {
                c.upsert({key: "de-DE"}).then(() => {
                    console.log("inserted")
                })
            })
        } else {
            db["language"].findOne().exec().then((res) => {
                console.log("found", res)
            })
        }
    })

我的问题是,在应用程序重新加载时找不到创建的集合“语言”。代码总是执行 if 路径而不是我期望的 else 路径。

我在这里做错了什么? 谢谢帮忙!

【问题讨论】:

    标签: typescript indexeddb rxdb


    【解决方案1】:

    您必须在每次重新启动应用程序时调用 collection() 方法。 RxCollection-instance 不会自动创建。

    【讨论】:

    • 感谢您的帮助!当我阅读文档时,这对我来说并不明显,但如果你仔细想想,这是有道理的,因为 db 以相同的方式处理它。
    猜你喜欢
    • 2013-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-01
    • 2014-08-29
    • 1970-01-01
    相关资源
    最近更新 更多