grahamearley / FirestoreGoogleAppsScript

A Google Apps Script library for accessing Google Cloud Firestore.
http://grahamearley.website/blog/2017/10/18/firestore-in-google-apps-script.html
MIT License
648 stars 109 forks source link

Get error message when calling 'getDocument' on an empty document #138

Open zhezhang77 opened 2 years ago

zhezhang77 commented 2 years ago

Minimal code to reproduce the problem

Create an empty document (no fields) in the firestore "test_col/test_doc"

const firestore = FirestoreApp.getFirestore(email, key, projectId);
firestore.createDocument('test_col/test_doc', {});
var data = firestore.getDocument('test_col/test_doc');

Expected Behavior

'data' should be valid and 'data.obj' = {}

Actual Results

Get the error message when calling 'getDocument':

Error: No document with `fields` found at path test_col/test_doc
getDocument_    @ FirestoreRead.gs:76
getDocument @ Firestore.gs:44
Library Version:

v33

LaughDonor commented 2 years ago

I don't think the library handles empty documents like that. I'm curious to a valid use case, @zhezhang77.

zhezhang77 commented 2 years ago

I don't think the library handles empty documents like that. I'm curious to a valid use case, @zhezhang77.

An empty document in the database indicates that a site exists but has no record right now. I understand that I can change the fields definition of the document to avoid creating an empty one, but it's a risky action to upgrade the whole database and codes in other clients (Python, C#, etc).

Since there is no restriction to create an empty document on all platforms including FirestoreApp, I think it is reasonable to read that document out without throwing any errors.