xblaz3kx
xblaz3kx

Reputation: 371

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. This is my Node.js code and it currently works even tho it's got no proper responses.

    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. Using FirestoreRecyclerView and an RecyclerView custom adapter and class. I tried ServerTimeStamp and double checked variable names, sequence and I still get a null object. I get proper productID and status values.

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?

Upvotes: 1

Views: 382

Answers (1)

Zohaib Amir
Zohaib Amir

Reputation: 3562

You need to include the default empty constructor and getters for all fields. If only your timestamp is null, then you must not have a getter for timestamp.

Upvotes: 2

Related Questions