0

I have to display the message from start date to end date ..Once end date is over ,message should disable..I have tried to match but am not getting the values..Kindly help me in this issue..Thanks in Advance

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)


            });
    });
Vishnu
  • 745
  • 12
  • 32
  • Possible duplicate of [MongoDb query condition on comparing 2 fields](https://stackoverflow.com/questions/4442453/mongodb-query-condition-on-comparing-2-fields) – Alex Blex Dec 01 '17 at 09:16
  • I am using 3.2 MongoDB and i am having start and end date in second collection – Vishnu Dec 01 '17 at 09:20
  • 1
    Yes, indeed, the previous answer doesn't provide copy and paste solution, but please put some effort in it. Read and comprehend all answers of the previous question, not only the accepted one. Number of collections doesn't matter. Aggregation is a pipeline, it works with stages. Collections come in play only on first stage, lookup stages, and output. All other stages take output of the previous one as input, and it doesn't matter from how many collections it came. `$cmp` is available since 2.4, if not earlier. With 3.2 you can't use `$addField`, but it is not critical and can be worked around – Alex Blex Dec 01 '17 at 10:14
  • Thank you for your response.. ll try – Vishnu Dec 01 '17 at 10:16

0 Answers0