[英]Retrieving null object from Firestore when its not actually null
I've been trying to understand why my query returns null object from server generated timestamp value. 我一直试图理解为什么我的查询从服务器生成的时间戳值中返回空对象。
Basically, I used onUpdate() trigger on my Firestore database and check, if the product is low on stock and make a reminder when the stock is <=5. 基本上,我在Firestore数据库上使用了onUpdate()触发器,并检查产品库存是否不足,并在库存量小于等于5时发出提醒。 This is my Node.js code and it currently works even tho it's got no proper responses.
这是我的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;
}
});
Server successfully inserts the generated timestamp and even when manually added, It still retrieves a null object in Java/Android. 服务器成功插入了生成的时间戳,即使手动添加了时间戳,它仍会在Java / Android中检索空对象。 Using FirestoreRecyclerView and an RecyclerView custom adapter and class.
使用FirestoreRecyclerView和RecyclerView自定义适配器和类。 I tried ServerTimeStamp and double checked variable names, sequence and I still get a null object.
我尝试了ServerTimeStamp并仔细检查了变量名,序列,但仍然得到一个空对象。 I get proper productID and status values.
我得到正确的productID和状态值。
public reminderFirestore(Timestamp date, String productID, String status) {
this.productID = productID;
this.date = date;
this.status = status;
}
Has this something to do with my constructor and object type or did I mess up in the server/Node.js code? 这与我的构造函数和对象类型有关吗,还是我弄乱了server / Node.js代码?
You need to include the default empty constructor and getters for all fields. 您需要为所有字段包括默认的空构造函数和getter 。 If only your timestamp is null, then you must not have a getter for timestamp.
如果只有您的时间戳为null,则您必须没有getter的时间戳。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.