Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 云函数使用来自不同节点模块的GeoPoint类_Javascript_Firebase_Google Cloud Firestore_Google Cloud Functions - Fatal编程技术网

Javascript 云函数使用来自不同节点模块的GeoPoint类

Javascript 云函数使用来自不同节点模块的GeoPoint类,javascript,firebase,google-cloud-firestore,google-cloud-functions,Javascript,Firebase,Google Cloud Firestore,Google Cloud Functions,我正在运行firebase云函数和firebase firestore。 尝试将地质点实例存储到firestore时,firebase上记录了以下错误: Error: Argument "data" is not a valid Document. Detected an object of type "GeoPoint" that doesn't match the expected instance. Please ensure that the Firestore types you ar

我正在运行firebase云函数和firebase firestore。 尝试将地质点实例存储到firestore时,firebase上记录了以下错误:

Error: Argument "data" is not a valid Document. Detected an object of type "GeoPoint" that doesn't match the expected instance. Please ensure that the Firestore types you are using are from the same NPM package.
at Object.exports.(anonymous function) [as isDocument] (/user_code/node_modules/firebase-admin/node_modules/@google-cloud/firestore/src/validate.js:86:15)
at WriteBatch.set (/user_code/node_modules/firebase-admin/node_modules/@google-cloud/firestore/src/write-batch.js:286:14)
at DocumentReference.set (/user_code/node_modules/firebase-admin/node_modules/@google-cloud/firestore/src/reference.js:420:8)
at exports.initializeActivityStructure.functions.firestore.document.onCreate (/user_code/lib/index.js:86:33)
at Object.<anonymous> (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:112:27)
at next (native)
at /user_code/node_modules/firebase-functions/lib/cloud-functions.js:28:71
at __awaiter (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:24:12)
at cloudFunction (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:82:36)
at /var/tmp/worker/worker.js:716:24
我在这里尝试了不同的版本,并确定了离线执行代码时可以正常工作的版本

以下是引发错误的代码:

import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';
import * as spacetime from 'spacetime';
import { DocumentSnapshot, GeoPoint } from '@google-cloud/firestore';
admin.initializeApp();

...

export const newDocument = functions.firestore.document('/someCollection/{documentKey}').onCreate((snapshot, context) => {
    return snapshot.ref.set({
        gps: new GeoPoint(10.0, 10.0),
       ...
    });
}

我非常感谢您对此的任何意见,因为很明显这是某种依赖性问题,但完全相同的版本在脱机测试时工作。

使用
gps:new firebase.firestore.GeoPoint(10.0,10.0)

尝试使用
firebase.firestore.GeoPoint
而不仅仅是
GeoPoint
使用
admin.firestore.GeoPoint
(来自firebase admin)工作。仍然想知道这是预期用途还是一个bug,因为不使用它们最初在中声明的包中的类似乎有点奇怪。上面的更正:使用
admin.firestore.GeoPoint
可以保存GeoPoint,但在这之后,任何操作(如更改侦听器)都可以保存在该文档上抛出异常
错误:参数“latitude”不是有效数字。at Object.exports.(匿名函数)[as isNumber](/user\u code/node\u modules/firebase admin/node\u modules/@google cloud/firestore/src/validate.js:86:15)
。仅从文档中删除属性(手动)并在web界面中重新添加新的地理点即可解决此问题。我还面临错误:尝试从firestore检索时,参数“latitude”不是有效的数字错误。你能解决这个问题吗?有什么原因吗?
import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';
import * as spacetime from 'spacetime';
import { DocumentSnapshot, GeoPoint } from '@google-cloud/firestore';
admin.initializeApp();

...

export const newDocument = functions.firestore.document('/someCollection/{documentKey}').onCreate((snapshot, context) => {
    return snapshot.ref.set({
        gps: new GeoPoint(10.0, 10.0),
       ...
    });
}