查询一个集合值并发送其他集合值

时间:2016-07-19 12:27:17

标签: node.js mongodb

每个人,我有两个架构,一个是年龄,第二个是我试图从我的年龄计划中找到年龄并与年龄相匹配的问题 如果年龄是真的,那么它会向我发送第二个集合中的问题 但它的加载......并且什么也没显示

1)。节点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 a = 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 the 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;

 })();

0 个答案:

没有答案