我无法使用Java脚本在Firebase云数据库中添加和编辑数据。我能够选择数据但无法添加数据

时间:2018-07-21 08:50:27

标签: javascript database firebase cloud

看到我使用以下代码添加数据

db.collection("users").add({
                            email: $('#emailaddress-register').val(),
                            password: $('#password-register').val()
                         }).then((done) => {
                             alert('Account created sucessfully'+done);
                         }).catch(function (error) {
                              console.error('Error adding document: ', error)
                         });

1 个答案:

答案 0 :(得分:1)

好吧,根据您提供的信息:

 var config = {
          apiKey: "",
          authDomain: "",
          databaseURL: "",
          projectId: "",
          storageBucket: "",
          messagingSenderId: ""
        };
        firebase.initializeApp(config);
        const firestore = firebase.firestore();
        const settings  = {timestampsInSnapshots: true};

        firestore.settings(settings);
        let db = firebase.firestore();

它仅需要一个Firestore实例:

var config = {
      apiKey: "",
      authDomain: "",
      databaseURL: "",
      projectId: "",
      storageBucket: "",
      messagingSenderId: ""
    };
    firebase.initializeApp(config);
    const db = firebase.firestore();
    const settings  = {timestampsInSnapshots: true};                
    db.settings(settings);

然后,您可以使用所获得的东西。