Hey everyone,
I am using meteor with react-komposer and I am having issues with a subscription. I have a method that will return a question, answers, and userResponses, and the behavior that I notice is that if I console.log the props as they come in, I will get answers initially but then I will get a bunch of empty answer sets even though meteor toys says that answers are present. What’s weird is that my userResponses always comes back correct, but my answers does not even though I treat them equivalently in my methods. Thanks!
Meteor.publish('createAndGetUserResponses', function (questionId) {
const userId = this.userId;
check(questionId, String);
check(userId, String);
const answers = Answers.find({ questionId });
const answersCount = Answers.find({ questionId }).fetch();
const userAnswers = UserAnswer.find({ userId, questionId }).count();
if (answers !== null && userAnswers !== null && answersCount !== null) {
if (userAnswers === 0) {
answers.forEach((answer) => {
UserResponses.insert({ a new user response });
});
}
return [
UserResponses.find({ userId, questionId }),
Answers.find({ questionId }),
Questions.find({_id: questionId }),
];
}
});
This is my react-komposer container:
const composer = (params, onData) => {
const { courseName, sectionName, lectureName } = params;
const subscription = Meteor.subscribe('getLecture', courseName, sectionName, lectureName)
if (subscription.ready()) {
const lecture = Lectures.findOne();
const { currentQuestionId } = userLecture;
const userAnswersSubscription =
Meteor.subscribe('createAndGetUserResponses', currentQuestionId);
if (userAnswersSubscription.ready()) {
const question = Questions.findOne();
const userResponses = UserResponses.find({}).fetch();
const answers = Answers.find({}, { sort: { group: 1, position: 1 } }).fetch();
onData(
null,
{question, answers, userResponses }
);
}
}
};