last day (15 days later) » 

10:32 PM
0
A: How do I compare a value of a local MongoDB collection to a regular MongoDB collection?

challettThis issue is coming forth because in Mongo the _id of the object is passed along with the specified fields and the way that javascript handles object equality. Just because two objects have the same fields and values does not mean that object1 === object2 will return true. Instead, you should ...

 
Yeah, tried this before but still gives the same message.
 
As kyll mentioned, you have two issues. My latest code block should solve both of them
 
Still get the same result. I tried this same method yesterday as well, since the id variable is empty outside the insert callback.
 
Well let's find out why then. Edit your question to include the output from console.log(Answers.findOne({_id: id}, {answer: 1, _id: 0})) and console.log(Quiz.findOne({_id: currentId},{answer:1, _id: 0})) inside of your equality if statement
 
Console logging it inside the if statement brings no error. It prints both the collections with their keys.
 
10:32 PM
A third problem with your code is object equality in javascript. var cat1 = {name:'cat'}, cat2 = {name:'cat'} cat1 === cat2 will output false. See my latest edit .
 
quizSubmission.answer is undefined inside the if statement.
 
You need to find out what Quiz.findOne({_id: this._id},{answer:1})) is then, if it doesnt have an answer field then you have something else going on
I forgot to transfer a small bit of code to the third code block. it's undefined because your findOne wasn't finding anything because you lost your data context (this). I'm now using currentId variable that I defined before the insert
so try my latest code
 
alright, thanks
 
No problem, sorry this took so many edits.
 
no problem man
thanks for all your help
 
10:39 PM
Is it working now?
 
nope
but the console log of the Quiz works
so it's not the variable itself that's broken nor is it the collection
 
is the value of the answer field a string?
 
yes
just a dummy question + answers
 
can you show me both of them?
 
that's the local one
oh fuck
fuck
 
10:42 PM
okay the final problem is what you just realized
 
now I see the problem
DAMNIT
 
I'm not going to say anything haha.
 
no wonder nothing works
 
even with the matching strings, your original code wouldn't have worked
 
FFFFFFUUUUUUUUUUUUUUU
 
10:43 PM
but with the code in my answer it should work
 
yeah man I was wondering why
wow i'm stupid
also
 
no worries, it's easy to overlook the small things when you're focused
 
let me pick your brain a little bit
 
I am heading out shortly
 
alright
thanks for the help man
 
10:44 PM
But I can answer anything another time
Best
 
i'll see you around I'm sure
peace out mane
 

last day (15 days later) »