0

Trying to start with RxDB in my angular application. Wanted to get something simple to work:

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)
            })
        }
    })

My problem is, that the created collection "language" won't be found on application reload. The code always executes the if-path not the else path like I was expecting.

What I'm doing wrong here? Thx for help!

1 Answers1

0

You have to call the collection()-method on each restart of your application. The RxCollection-instance will not be created automatically.

pubkey
  • 617
  • 8
  • 17
  • Thanks for helping! It was not obvious to me when I read the documentation but if you think about it, it makes sense, because the db handles it the same way. – user9316588 Sep 10 '19 at 09:10