【问题标题】:Checking if value is in database seems doesn't work检查值是否在数据库中似乎不起作用
【发布时间】:2022-01-03 21:00:40
【问题描述】:

我想编写一个函数来检查特定值是否在 firebase 数据库中,然后在存在时执行某些操作,在不存在时执行其他操作。但我收到Uncaught TypeError: db._checkNotDeleted is not a function 错误。我不知道为什么。

js:

    const onBuyHandler = (event) => {
    const db = getDatabase();
    ref(`users/${user.uid}/items/kitchen/${props.item.name}`).once(
        'value',
        (snapshot) => {
            if (snapshot.exists()) {
            } else {
                set(
                    ref(
                        db,
                        `users/${user.uid}/items/kitchen/${props.item.name}`
                    ),
                    {
                        name: props.item.name,
                        amount: 1,
                    }
                );
            }
        }
    );
};

【问题讨论】:

    标签: javascript firebase firebase-realtime-database


    【解决方案1】:

    ref() 中的第一个参数必须是数据库实例。

    const db = getDatabase();
    ref(db, `users/${user.uid}/items/kitchen/${props.item.name}`)....
    // ^^^ add db here
    

    【讨论】:

    • 现在我收到了Uncaught TypeError: (0 , firebase_database__WEBPACK_IMPORTED_MODULE_3__.ref)(...).once is not a function
    猜你喜欢
    • 1970-01-01
    • 2023-04-06
    • 1970-01-01
    • 2018-08-29
    • 1970-01-01
    • 2015-02-02
    • 2012-04-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多