RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / 问题

问题[firebase]

Martin Hope
avldokuchaev
Asked: 2023-06-04 07:03:08 +0000 UTC

当文档的创建时间与今天的日期不同时,如何编写一个函数从 firebase 中删除数据?

  • 5

我有一个使用 firebase 的 swiftui 应用程序。

创建文档时,数据库中存储了 2 个可选参数:一个数组upPostPlusDay和一个计数器upPostPlusDayValueCount,以及创建文档的日期publishedDate( timestamp)。

请帮我写一个函数,如果文档创建日期和今天的日期有差异,例如7天,数组值将被删除,计数器值将被重置。

一个数组只能包含一个值。

这是将参数写入数据库的模型代码:

import SwiftUI
import FirebaseFirestoreSwift

struct Post: Identifiable, Codable, Equatable, Hashable {
    @DocumentID var id: String?
    var text: String
    var postHead: String
    var postAddress: String
    var imageURL: URL?
    var imageReferenceID: String = ""
    var publishedDate: Date = Date()
    var likedIDs: [String] = []
    var dislikedIDs: [String] = []
    var plusFavorites: [String] = []
    var upPostPlusDay: [Int] = []
    var upPostPlusDayValueCount: Double = 0
    var userName: String
    var userUID: String
    var userProfileURL: URL
    var userBioLink: String
    
    enum CodingKeys: CodingKey {
        case id
        case text
        case postHead
        case postAddress
        case imageURL
        case imageReferenceID
        case publishedDate
        case likedIDs
        case dislikedIDs
        case plusFavorites
        case upPostPlusDay
        case upPostPlusDayValueCount
        case userName
        case userUID
        case userProfileURL
        case userBioLink
    }
}
firebase
  • 1 个回答
  • 18 Views
Martin Hope
Anton Buketov
Asked: 2022-06-26 16:06:39 +0000 UTC

Firebase + react - db._checkNotDeleted 不是函数如何修复

  • 0

我不明白问题出在哪里,我什至无法上传测试数据。

firebase.js

import { initializeApp } from 'firebase/app'
import {getAuth} from 'firebase/auth'

const firebaseConfig = {
  apiKey: "---",
  authDomain: "---",
  databaseURL: "---",
  projectId: "---",
  storageBucket: "---",
  messagingSenderId: "---",
  appId: "---"
}


// Initialize Firebase and Firebase Authentication
const app = initializeApp(firebaseConfig)
const auth = getAuth(app)
export {auth}

ProfileEdit.js

import { useAuthValue } from './AuthContext'
import { signOut } from 'firebase/auth'
import { getDatabase, ref, child, push, update,set } from "firebase/database";
import React, { useState, useEffect } from 'react';
import xtype from 'xtypejs'

import { auth } from './firebase'




function ProfileEdit() {
  const { currentUser } = useAuthValue();

  const db = ref(getDatabase());


  const [name, setName] = useState()
  const [phone, setPhone] = useState()
  const [payment, setPayment] = useState()
  const [address, setAddress] = useState()

  const Submit = () => {
      
     const postData = {
      address: "test",
      firstName: "test",
      paymentByCard: "test",
      phone: "test",
  
    };

    const data = {}
    data["users/" + currentUser?.uid] = postData
    console.log(data)
    return update(ref(db,data))
  }
  console.log(currentUser?.uid)



  return (


    <form action="" className="profile-filling" >
      <input type="text" name={"name"} id="" placeholder="Enter your  firstname" />
      <input type="text" name={"address"} id="" placeholder="Enter your  Address" />
      <input type="text" name={"phone"} id="" placeholder="Enter your  phoneNumber" />

      <div>
        <span>  Credit cart? </span>
        <input type="checkBox" name={"payment"} id="" placeholder="Enter your  firstname" />
        <span>Cahs?</span>
        <input type="checkBox" name={"payment"} id="" placeholder="Enter your  firstname" />
      </div>
      <span onClick={Submit}>Submit</span>
    </form>
  )
}

export default ProfileEdit
reactjs firebase
  • 1 个回答
  • 32 Views
Martin Hope
Anton Buketov
Asked: 2022-06-21 00:22:06 +0000 UTC

我通常如何从 Firebas 获取数据并在 html 标签中显示数据

  • 0

如何从 firebase 获得正常响应。我尝试过这样的事情:

      const db  =  ref(getDatabase(),'Restaurants/');
      let data = []
      onValue(db, (snapshot) => {
        data = snapshot.val();
        return data
      });
      console.log(data)

然后我将它放入一个新数组中:

  let list = []
  for( let i =0;i<=data.length;i++){
    if (data[i] === undefined){
      continue
    }
    else{
      console.log(data[i])
      list.push(data[i])
    }

  }

结果我得到: 在此处输入图像描述

我正在尝试像这样显示 html 标记:

  return(
    <div className="restaraunts">
      {list.map((restaraunt) => (
      <div className="restaraunt-info">
        <span className="restaraunt-name"> {restaraunt.name}</span>
        <span className="restaraunt-desc"> {restaraunt.name}</span>
        <span className="restaraunt-price">{restaraunt.name}</span>
        <span className="restaraunt-time">{restaraunt.name}</span>
        <span className="restaraunt-logo"> {restaraunt.name}</span>
      </div>
      ))}
    </div>
  )

完整代码:

import React from 'react';
import {useState} from 'react'
import { getDatabase, ref, child, get,onValue } from "firebase/database";




function Restaraunts(){

  const db  =  ref(getDatabase(),'Restaurants/');
  let data = []
  onValue(db, (snapshot) => {
    data = snapshot.val();
    return data
  });
  console.log(data)


  let list = []
  for( let i =0;i<=data.length;i++){
    if (data[i] === undefined){
      continue
    }
    else{
      console.log(data[i])
      list.push(data[i])
    }

  }
  console.log(list)
  return(

    <div className="restaraunts">
      {list.map((restaraunt) => (
      <div className="restaraunt-info">
        <span className="restaraunt-name"> {restaraunt.name}</span>
        <span className="restaraunt-desc"> {restaraunt.name}</span>
        <span className="restaraunt-price">{restaraunt.name}</span>
        <span className="restaraunt-time">{restaraunt.name}</span>
        <span className="restaraunt-logo"> {restaraunt.name}</span>
      </div>
      ))}
    </div>
  )
}

export default Restaraunts

我刚开始使用 react 和 firebase。主要问题是为什么我得到一个空数组?以及如何以 HTML 格式输出所有接收到的数据。

reactjs firebase
  • 1 个回答
  • 48 Views
Martin Hope
Xyanight
Asked: 2022-04-15 04:06:16 +0000 UTC

为什么 Firebase 返回 requests.exceptions.ConnectionError: HTTPSConnectionPool?

  • 0

这就是问题所在:我有一个使用 Firebase 的实时数据库的应用程序。直到最近一切都很好。就在一周前,他们开始闹翻requests.exceptions.ConnectionError: HTTPSConnectionPool。对数据库的任何请求,但每隔一次。有时返回数据,有时不返回。此外,问题出现在哈萨克斯坦(我的应用程序在那里工作)。例如,在罗斯托夫,该程序继续运行而没有错误。我已经增加了请求超时:

self.app = firebase_admin.initialize_app(
    self.credentials,
        {
            ...,
            "httpTimeout": 320,
        },
)

并在请求中添加了标头:

HEADER = {
    "User-Agent": "Mozilla/5.0 "
    "(Windows NT 10.0; Win64; x64) "
    "AppleWebKit/537.36 (KHTML, like Gecko) "
    "Chrome/70.0.3538.77 Safari/537.36"
}

但是这些错误继续随着时间流逝:

    requests.exceptions.ConnectionError: HTTPSConnectionPool(
        host='name-base.firebaseio.com', port=443):
            Max retries exceeded with url: /name-base/Path/To/Data.json (
                Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x0000021F1779F310>:
                    Failed to establish a new connection: [WinError 10060]
                    попытка установить соединение была безуспешной,
                    т.к. от другого компьютера за требуемое время не получен нужный отклик,
                    или было разорвано уже установленное соединение из-за неверного отклика уже подключенного компьютера'))

此外,如果你except在分支中捕获了异常并再次发送请求,那么第二个请求将返回数据:

    def get_request(self, date_request: str) -> NoReturn:
        try:
            self.real_time_firebase.get_request(
                f"{self.type_base}/{self.name_base_registry}",
                date_request,
                headers=HEADER,
            )
        except requests.exceptions.ConnectionError:
            self.get_request(date_request)

以下代码:

import requests
from firebase import firebase


class Base:
    def __init__(self):
        self.real_time_firebase = firebase.FirebaseApplication(
            "https://loginappmvc-5a4aa-default-rtdb.firebaseio.com/", None
        )
        self.type_base = "UserData"
        self.name_base_users = "LoginsPasswords"

    def get_data_from_base_users(self):
        try:
            data = self.real_time_firebase.get(self.type_base, self.name_base_users)
        except requests.exceptions.ConnectionError:
            return None
        return data


base = Base()
for i in range(20):
    print(base.get_data_from_base_users())

...满足卢甘斯克的所有要求:

在此处输入图像描述

但是从哈萨克斯坦运行的相同代码崩溃了五次,并出现 ConnectionError:

在此处输入图像描述

谁知道可能发生了什么?

firebase
  • 1 个回答
  • 10 Views
Martin Hope
rulila52
Asked: 2022-09-18 08:09:00 +0000 UTC

通过 Microsoft 获得 Firebase Flutter 授权

  • 0

是否可以通过firebase和微软在flutter中实现授权?Firebase 文档提到了不同的社交网络,但没有提到 Microsoft,但它存在于 Firebase 控制台的授权方法中

firebase
  • 1 个回答
  • 10 Views

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    我看不懂措辞

    • 1 个回答
  • Marko Smith

    请求的模块“del”不提供名为“default”的导出

    • 3 个回答
  • Marko Smith

    "!+tab" 在 HTML 的 vs 代码中不起作用

    • 5 个回答
  • Marko Smith

    我正在尝试解决“猜词”的问题。Python

    • 2 个回答
  • Marko Smith

    可以使用哪些命令将当前指针移动到指定的提交而不更改工作目录中的文件?

    • 1 个回答
  • Marko Smith

    Python解析野莓

    • 1 个回答
  • Marko Smith

    问题:“警告:检查最新版本的 pip 时出错。”

    • 2 个回答
  • Marko Smith

    帮助编写一个用值填充变量的循环。解决这个问题

    • 2 个回答
  • Marko Smith

    尽管依赖数组为空,但在渲染上调用了 2 次 useEffect

    • 2 个回答
  • Marko Smith

    数据不通过 Telegram.WebApp.sendData 发送

    • 1 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5