Need help in comparing input from local MongoDB collection to regular Mongo collection


#1

Basically, I’m trying to compare the user’s answer for a question in a “null” or local MongoDB to a key in another MongoDB that was declared before.

This is the code I have thus far:

Template.question.events({
“click .button”: function(e){
e.preventDefault;

var init ="";
for (var i = 0; i < document.getElementsByName("choices").length; i++){
  if (document.getElementsByName("choices")[i].checked){
    init = document.getElementsByName("choices")[i].value;
  }
}
var id = "";
Answers.insert({answer: init}, function(error, result){
  if (error){
    console.log("error: " + error);
  } else if (result){
    id = result;
  }
})
if(Answers.findOne({_id: id}, {answer:1}) === Quiz.findOne({_id: this._id},{answer:1})){
  console.log("The answers match.");
} else{
  console.log("Something went wrong.");
}

}

});

I’m stuck at the last part, where I try to compare the user’s answer, which is housed at a local MongoDB, to the answer, which is housed at a regular collection. They both have the answer keys and they are both the same. No matter what I do, the console always prints “Something went wrong.” I tried so many different combinations and still have the same problem.

Any help would be appreciated.