exports.cloneUsers = functions.database.instance('ams4-contract').ref('/users/{user_id}').onWrite(event => {
//exports.cloneUsers = functions.database.ref('/users/{user_id}').onWrite(event => {
let user_data = event.data.val();
let user_id = event.params.user_id;
console.log('event usr ' + event.timestamp);
console.log('Indexing usr ' + user_id + ' ' + user_data);
let elasticSearchFields = ['name', 'nick', 'martial art'];
let elasticSearchConfig = functions.config().elasticsearch;
let elasticSearchUrl = elasticSearchConfig.url + 'users/user/' + user_id;
let elasticSearchMethod = user_data ? 'POST' : 'DELETE';
let elasticSearchRequest = {
method: elasticSearchMethod,
uri: elasticSearchUrl,
auth: {
username: elasticSearchConfig.username,
password: elasticSearchConfig.password
},
body: _.pick(user_data, elasticSearchFields),
json: true
};
return request(elasticSearchRequest).then(response => {
console.log('Elasticsearch response', response);
})
});

当我使用functions.database.ref
时,
它可以获得event.params.user_id
它可以更新elasticsearch complete。
但请使用functions.database.instance('ams4-contract')
event.params.user_id
未定义!
此日志
functions.database.ref
的日志ID 36608977830579
functions.database.instance('ams4-contract')
的日志ID 36604231411908
谢谢。
答案 0 :(得分:0)
这似乎是一个错误。您现在可以通过在使用instance()时删除ref字符串中的前导斜杠来解决它:
exports.cloneUsers = functions.database.instance('ams4-contract')
.ref('users/{user_id}')
我在内部使用Firebase提交了一个错误。您可以自己file a bug report随意。