android - 从 Firestore 中检索 null 对象,当它实际上不是 null

标签 android node.js google-cloud-firestore google-cloud-functions

我一直在努力理解为什么我的查询从服务器生成的时间戳值返回空对象。

基本上,我在我的 Firestore 数据库上使用了 onUpdate() 触发器,并检查产品是否库存不足,并在库存 <=5 时发出提醒。这是我的 Node.js 代码,即使没有得到正确的响应,它目前也能正常工作。

    const date = admin.firestore.FieldValue.serverTimestamp();
    const reminder = {
      productID : product.barcode,
      date : date,
      status: 'Order'
  }

      const docSnapShot = admin.firestore().collection('reminders').doc(product.barcode).get().then(documentSnapShot =>{
          if(documentSnapShot.exists){
            return admin.firestore().collection('reminders').doc(product.barcode).update({date: date}).then(res=> {
              console.log('Document updated');
              return null;
            }).catch(error =>{
              console.log('Error',error);
              return null;
            });
          }
          else{
            exists = docSnapShot.exists;
            return null;
          }
      });

服务器成功插入生成的时间戳,即使手动添加,它仍然在 Java/Android 中检索到空对象。使用 FirestoreRecyclerView 和 RecyclerView 自定义适配器和类。我尝试了 ServerTimeStamp 并仔细检查了变量名、序列,但我仍然得到一个空对象。我得到了正确的 productID 和状态值。

public reminderFirestore(Timestamp date, String productID, String status) {
    this.productID = productID;
    this.date = date;
    this.status = status;
}

这与我的构造函数和对象类型有关,还是我弄乱了服务器/Node.js 代码?

最佳答案

您需要为所有字段包含默认的空构造函数和getters。如果只有你的时间戳为空,那么你不能有时间戳的 getter。

关于android - 从 Firestore 中检索 null 对象,当它实际上不是 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57437967/

相关文章:

android - 如何在 Android 中找出运营商的名称

java - 是否可以从 maven 编译 grunt 项目?

node.js - 从未使用redis在child_process.exec中调用回调

JavaScript 过滤来自 Firestore 的数据

android - ionic 角: opening links in (external) mobile browser

android - ViewPager FragmentPagerAdapter 只更新最后一个 fragment onNavigationItemSelected

android - CardView 填充和圆角

向我的 Node 服务器发送 AJAX 请求 - 未通过

javascript - firestore 中的查询数组

java - Firestore 无法添加 DocumentId