不支持的字段值:一个函数(在字段creationTime中找到)

时间:2019-02-28 08:12:45

标签: angular typescript firebase google-cloud-firestore ionic4

user-profile.ts

SELECT number, type
FROM numbers
WHERE (number <=5 AND type=1) OR
      (number > 5 AND type=2)
ORDER BY type ASC, ABS(number-5) ASC
LIMIT 1

service.ts

export interface UserProfile {
    id: string;
    name: string;
    email: string;
    phone?: string;
    creationTime?: any;
}

控制台上的一个错误:

  

[2019-02-28T08:01:58.804Z] @ firebase / firestore:Firestore(5.8.3):
  现在,timestampsInSnapshots设置默认为true,而您不设置
  不再需要显式设置它。在以后的版本中,该设置
  将被完全删除,因此建议您删除它
  现在从您的firestore.settings()调用。

这是下一个错误:

  

FirebaseError:函数DocumentReference.set()调用无效   数据。不支持的字段值:一个函数(在字段中找到   creationTime)       在新的FirestoreError(http://localhost:8100/vendor.js:77381:28)       在ParseContext.push ../ node_modules/@firebase/firestore/dist/index.cjs.js.ParseContext.createError   (http://localhost:8100/vendor.js:96125:16)       在UserDataConverter.push ../ node_modules/@firebase/firestore/dist/index.cjs.js.UserDataConverter.parseScalarValue中   (http://localhost:8100/vendor.js:96467:27)       在UserDataConverter.push ../ node_modules/@firebase/firestore/dist/index.cjs.js.UserDataConverter.parseData中   (http://localhost:8100/vendor.js:96338:29)       在http://localhost:8100/vendor.js:96354:41       在forEach(http://localhost:8100/vendor.js:77483:13)       在UserDataConverter.push ../ node_modules/@firebase/firestore/dist/index.cjs.js.UserDataConverter.parseObject中   (http://localhost:8100/vendor.js:96353:13)       在UserDataConverter.push ../ node_modules/@firebase/firestore/dist/index.cjs.js.UserDataConverter.parseData中   (http://localhost:8100/vendor.js:96312:25)       在UserDataConverter.push ../ node_modules/@firebase/firestore/dist/index.cjs.js.UserDataConverter.parseSetData中   (http://localhost:8100/vendor.js:96177:31)       在DocumentReference.push ../ node_modules/@firebase/firestore/dist/index.cjs.js.DocumentReference.set   (http://localhost:8100/vendor.js:97049:45

1 个答案:

答案 0 :(得分:2)

您需要执行以下操作:

第一个错误: https://github.com/angular/angularfire2/issues/1993#issuecomment-456481677

第二个错误:

  const userProfile: UserProfile = {
    id: user.user.uid,
    email: email,
    creationTime: firebase.firestore.FieldValue.serverTimestamp(),
    name: name
  };

如文档中所述,firebase.firestore.FieldValue.serverTimestamp()将返回在构建要写入Firestore的对象时使用的“前哨”对象。它将向服务器指示应将其替换为实际的时间戳。