I want to find Users having some questions And after that I have to find questionId from question collection and then update the questionId to the user collection Here is the query which gives me undefined
db.users.find({
$and: [{
"question": {
"$ne": ""
}
}, {
"question": {
"$ne": null
}
}]
}).forEach(function(myDoc) {
if (myDoc.question) {
print("user_id " + myDoc.user_id + " " + myDoc.question)
var doc2 = db.security_que.findOne([{
$match: {
"que": myDoc.question
}
}]);
if (doc2) {
db.users.update({
"user_id": myDoc.user_id,
"question_id": myDoc.que_id
}, {
$set: {
"question_id": doc2.que_id
}
})
}
}
});