Firebase在文档更新时获取数据库值



当更新某些值时,我想在数据库中查找特定的值。然而,当我做firebase deploy时,我得到的是:

12 info lifecycle functions@~lint: Failed to exec lint script
13 verbose stack Error: functions@ lint: `tslint --project tsconfig.json`
13 verbose stack Exit status 2
13 verbose stack     at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:332:16)
13 verbose stack     at EventEmitter.emit (events.js:311:20)
13 verbose stack     at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:311:20)
13 verbose stack     at maybeClose (internal/child_process.js:1021:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5)
14 verbose pkgid functions@
15 verbose cwd /Users/u17495358/firecast
16 verbose Darwin 18.7.0
17 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "--prefix" "/Users/u17495358/firecast/functions" "run" "lint"
18 verbose node v12.16.1
19 verbose npm  v6.13.4
20 error code ELIFECYCLE
21 error errno 2
22 error functions@ lint: `tslint --project tsconfig.json`
22 error Exit status 2
23 error Failed at the functions@ lint script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 2, true ]

这是我的功能代码:

import * as functions from 'firebase-functions';
import admin = require('firebase-admin');
admin.initializeApp()
export const onLocationUpdate = 
functions.firestore.document("users/{userId}").onUpdate(
change => {
let data = change.before.data();
console.log(data);
for (const key in data) {
const value = data[key];
console.log(value);
}
change.before.ref.get().then(document => {
console.log(document.data);
})
let payload = {
data: {
temp: String(""),
conditions: String("")
}
}
return admin.messaging().sendToTopic("users", payload)
}
)

如果我删除这个,效果会很好:

change.before.ref.get().then(document => {
console.log(document.data);
})

问题出在哪里?我该如何解决?

如果我像这样添加catch(),它会起作用:

change.before.ref.get().then(document => {
console.log(document.data);
}).catch(error => console.log(error))

有趣的是,根据Firebase文档,据说不需要catch()

相关内容

  • 没有找到相关文章

最新更新