简体   繁体   English

即使成功响应,firebase数据库也不会更新

[英]firebase database not updating, even though successful response

I have a chat app that I am building in ionic and firebase. 我有一个聊天应用程序,正在用ionic和firebase构建。 I have a simple join channel function that takes the channel id, and adds the current user id to the list of member in the database. 我有一个简单的加入通道函数,该函数接受通道ID,并将当前用户ID添加到数据库中的成员列表中。 According to everything I am seeing it is working correctly, however whenever I go to the firebase console it is not showing the new item in the database. 根据我所看到的一切,它运行正常,但是,每当我进入Firebase控制台时,它都不会在数据库中显示新项目。 Here is the code I am using to add the item to the database when a user joins a chat channel... 这是当用户加入聊天频道时我用来将项目添加到数据库中的代码。

joinChannel(type, user_id) {
    return new Promise((resolve, reject) => {
      if(this.availableChannels[type] !== undefined) {
        console.log("joining channel: " + type);
        console.log('for user: ' + user_id);
        let update = {};
        update['/chat/members/' + type + '/' + user_id] = {active: true, joinedAt: firebase.database.ServerValue.TIMESTAMP};
        this.afDB.database.ref().update(update).then(() => {
          console.log("updated /chat/members/" + type + "/" + user_id + " to");
          console.log({active: true, joinedAt: firebase.database.ServerValue.TIMESTAMP});
          this.activeChannel = '/channels/' + type;
          resolve(true);
        })
      } else {
        reject("channel_not_found");
      }
    });
  }

Now, if I open up the developer console in chrome and click to join the channel I get this in the console... 现在,如果我打开Chrome中的开发者控制台并单击以加入频道,我将在控制台中看到它。

joining channel: news
chat.ts:210 for user: [USERIDHERE]
chat.ts:214 updated /chat/members/news/[USERIDHERE] to
chat.ts:215 Object
              active: true
              joinedAt: Object
                .sv: "timestamp"
              __proto__: Object
              __proto__: Object

So the console shows that the database ran the update, however if I then log into my firebase console, there is no "news" item in the "chat/members" database. 因此,控制台显示数据库运行了更新,但是如果我随后登录到Firebase控制台,则“聊天/成员”数据库中没有“新闻”项。 I have tried it with different channels, and always I get the same exact response from firebase, saying it updated the database, but in the firebase console that item remains blank. 我用不同的渠道尝试过它,并且始终能从firebase获得相同的准确响应,说它更新了数据库,但是在firebase控制台中,该项保持空白。

Just in case it is needed the this.afDB variable is public afDB: AngularFireDatabase in the constructor. 万一需要, this.afDB变量是public afDB: AngularFireDatabase构造函数中的public afDB: AngularFireDatabase I know the database is working because I can update things, send messages in chat channels and they appear in the firebase console, but for whatever reason, when a user joins a channel, I get the successful console log, but the database is not updating with the new information. 我知道数据库正在工作,因为我可以更新内容,在聊天频道中发送消息,并且它们会出现在Firebase控制台中,但是由于某种原因,当用户加入频道时,我会获得成功的控制台日志,但是数据库未更新与新的信息。 I am really lost on this one and could really use some help. 我真的迷失了这一点,可以真正使用一些帮助。

it seems to me you want to use a set instead of update 在我看来,您想使用集合而不是更新

 this.afDB.database.ref('/chat/members/' + type + '/' + user_id) .set({active: true, joinedAt: firebase.database.ServerValue.TIMESTAMP}); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 即使身份验证成功,也无法写入 firebase 实时数据库 - Unable to write to firebase realtime database even though authentication is successful 即使请求成功,获取的响应也为空 - fetch's response is empty even though the request was successful firebase 显示名称未在 UI 上更新,即使控制台显示它已在数据库中成功更新 - firebase displayName not updating on the UI even though console says it was updated successfully in the database 即使更新数据库,AJAX也不会成功 - AJAX not coming up a success even though its updating the database 即使请求成功,JSON ParseError也是如此 - JSON ParseError even though request was successful 即使列表是ngRepeat也不会更新 - ngRepeat not updating even though list is 访问已被 CORS 策略阻止,即使预检响应成功“Access-Control-Allow-Origin”通配符存在 - Access has been blocked by CORS policy even though preflight Response is successful 'Access-Control-Allow-Origin' wildcard exists 即使上传成功,Uploadify也将报告HTTP错误404 - Uploadify reporting HTTP ERROR 404, even though upload is successful 即使请求成功,使用 React 下载文件也会失败 - Download file with react failed even though the request was successful 即使注册成功,服务工作人员也显示为已删除 - service worker showing as deleted even though registration was successful
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM