如何使用mongoose执行$ match与第二个集合

时间:2017-12-01 08:58:21

标签: node.js mongodb date mongoose

我必须显示从开始日期到结束日期的消息..一旦结束日期结束,消息应该禁用..我试图匹配但是没有得到值..在这个问题上帮我解决。谢谢提前

mongo.notification.find({'clienttoken' : req.body.clienttoken},function(err,response){
        if (err) throw err
        console.log(response)
           console.log("get Request from Client")
             mongo.user.aggregate([
                {
                    $lookup:{
                        from:"notifications",
                        localField:"_id",
                        foreignField:"user_id",
                        as:"PersonName"
                            }
                },
                {
                    $match: {'clienttoken' : req.body.clienttoken , 'end_date':  { $gt:  'start_date', $lt:  'end_date'}
                }
                },
                {
                    $unwind:'$PersonName'
                },
                {
                "$project":{
                    "username":"$username",
                    "fname":"$fname",
                    "userid":"$_id",
                    "email":"$email",
                    "clienttoken" : "$clienttoken",
                    "message":"$PersonName.message",
                    "end_date" : "$PersonName.end_date",
                   "start_date":  "$PersonName.start_date"  
                    }
                }
                ]).exec(function(err, clientmsg){
                if (err) throw err; 
                res.json(clientmsg)


            });
    });

0 个答案:

没有答案