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

Prevent auto conversion to GeoPoint #156

Closed Stev3nsen closed 1 year ago

Stev3nsen commented 1 year ago

Hey guys, thanks for your awesome work. I have simple question. See below.

Minimal Code to Reproduce the Problem

const firestore = FirestoreApp.getFirestore(email, key, projectId);

function myFunction() {
  const document = {
    location: {
      "latitude": 10.1,
      "longitude": 10.1
    }
  }

  firestore.createDocument("Test", document)
}

Explain the Problem in Detail

When i create a document that contains a map with following structure

  const document = {
    "someName": {
      "latitude": 10.1,
      "longitude": 10.1
    }
  }

a document field gets some kind of auto converted to a geopoint type.

Expected result

image

In Firestore console i expected my location field as map structure and not as geopoint.

Actual result

image

The location field is automatically converted in a geopoint. Is there a way to prevent this behavior?

LaughDonor commented 1 year ago

It is automatic.. it works off of Duck Typing (source). If you don't want to do that, you'll have to rename the keys, or add an additional property since it's typically beneficial to use the built-in storage type that Firestore provides.