node.js - querying one collection value and send other collections values -
everyone, have 2 schema 1 age , second questions trying find age age scheme , match number of age , if age true sends me question second collection loading... , displaying nothing
1). node js
var agegroupquiz = require('../models/agegroupschema.js'); var questionquiz = require('../models/question.js'); exports.agegroupcontroller = function(req,res,next){ try{ var userobj = {}; var projection1 = '-id age_group.age_group_5.max_age'; var projection2 = '-id question'; var = agegroupquiz.findone(userobj,projection1); var age = 'a.age_group.age_group_5.max_age'; if(age===5){ questionquiz.find(userobj,projection2,function(err, data){ if(err){ console.log('getquestions : error while getting questions ' + err); return next(err); } //console.log(question); res.send(question); }); }else{console.log("error");} }catch(err){ console.log('error while saving reuslt ' +err); return next(err); } }
2). mongodb schema
a). var mongoose = require('mongoose'); module.exports = (function agegroup () { var schema = mongoose.schema; var agegroup = new schema({ age_group : { age_group_5: { _id:{type:string}, max_age:{type:number} } } }); var results = mongoose.model('age', agegroup); return results; })(); b). var mongoose = require('mongoose'); module.exports = (function question () { var schema = mongoose.schema; var question = new schema({ question:{type:array, _id:{type:number}, title:{type:string}, options:{type:array}, result:{type:array}, feedback:{type:string} }, metadata:{ type:string, category:string, age_group:string, location:string } }); var results = mongoose.model('userquestion', question); return results; })();
Comments
Post a Comment