Javascript 云函数不响应云Firestore中的onCreate

Javascript 云函数不响应云Firestore中的onCreate,javascript,firebase,google-cloud-firestore,google-cloud-functions,Javascript,Firebase,Google Cloud Firestore,Google Cloud Functions,我有一个index.js文件,其中包含以下内容: const functions = require('firebase-functions'); const trackVote = require('./trackVote') const admin = require('firebase-admin'); admin.initializeApp(); exports.trackVote = trackVote.handler; 然后,我引用以下函数: trackvote.js const

我有一个index.js文件,其中包含以下内容:

const functions = require('firebase-functions');
const trackVote = require('./trackVote')
const admin = require('firebase-admin');
admin.initializeApp();

exports.trackVote = trackVote.handler;
然后,我引用以下函数:

trackvote.js

const functions = require('firebase-functions');
const admin = require('firebase-admin');

exports.handler = functions.firestore.document('/Polls/{pollId}/responses/{userId}').onCreate((data, context) => {
           const answerSelected = data.data().answer;

           const answerRef = admin.firestore().doc(`Polls/${context.params.pollId}/answers/${answerSelected}`);
           const voteCountRef = admin.firestore().doc(`Polls/${context.params.pollId}`);

            return admin.firestore().runTransaction(t => {
                        return t.get(answerRef)
                            .then(doc => {
                                if (doc.data()) {
                                    t.update(answerRef, { vote_count: doc.data().vote_count + 1 });
                                }
                            })
                    }).then(result => {
                        return admin.firestore().runTransaction(t => {
                                    return t.get(voteCountRef)
                                        .then(doc => {
                                            if (doc.data()) {
                                                t.update(voteCountRef, {vote_count:doc.data().vote_count+1});
                                            }
                                        });
                                 });
                    });
    });
不幸的是,这个方法没有被调用,但是我知道我正在写入云Firestore中的特定位置。我的Firebase仪表板中也没有任何日志

以下是写入my Cloud Firestore的代码:

    mPollQuestionRadioGroup.setOnCheckedChangeListener(new 
    RadioGroup.OnCheckedChangeListener() {
    @Override
    public void onCheckedChanged(RadioGroup group, int checkedId) {

        disableVoteButtons(group);
        Toast.makeText(getActivity().getApplicationContext(), R.string.vote_submitted_label, Toast.LENGTH_LONG).show();

        voteOnPoll((Integer) group.findViewById(checkedId).getTag());

        //TODO: add animation between between vote click and chart display
        mPollQuestionRadioGroup.setVisibility(View.INVISIBLE);
        mPollResults.setVisibility(View.VISIBLE);
    }

});
方法:

 private void voteOnPoll(int checkedRadioButtonIndex) {
        int selectedAnswerIndex = checkedRadioButtonIndex + 1;
        HashMap<String, Object> firebaseAnswer = new HashMap<>();
        firebaseAnswer.put("answer", selectedAnswerIndex);
        mStoreBaseRef.collection("Polls").document(pollID).collection("responses").document(mUserID).set(firebaseAnswer);
    }
private void voteOnPoll(int checkedRadioButtonIndex){
int selectedAnswerIndex=checkedRadioButtonIndex+1;
HashMap firebaseAnswer=新HashMap();
firebaseAnswer.put(“回答”,选择回答索引);
mStoreBaseRef.collection(“Polls”).document(pollID).collection(“responses”).document(mUserID).set(firebaseAnswer);
}

当我在仪表板中检查我的Cloud Firestore时,我可以确认已成功写入此位置。

请编辑您的问题,以显示添加您希望调用此函数的文档的客户端代码。是否可以将控制台日志语句添加到您的函数中?在尝试使用客户端代码之前,您可能会尝试手动创建文档?您是否保存了该文件并将其部署到firebase?听起来很简单,但我以前就错过了。检查控制台中是否存在该功能?