sixmous-bruh
8/21/2019 - 12:04 PM

Mongo command for filtering referral count

//users who unlocked before july: 7 more days (after official announcement is made)  

[{"expire": 1566988355, "metadata": {"reply_remaining": 100}, "permission": "jobpool_reply"}, {"expire": 1566988355, "permission": "jobpool_instant_new_job_notify"}, {"expire": 1566988355, "permission": "jobpool_new_job_email"}, {"expire": 1566988355, "permission": "jobpool_job_record"}, {"expire": 1566988355, "permission": "jobpool_advance_filter"}, {"expire": 1566988355, "metadata": {"cancel": 1566384256, "premium_type": "plus"}, "permission": "premium_ac"}]

db.getCollection('referrals')
.find({
    $where:function() {
        if(this.admin_injected_count){
            if(this.receiver_objects){
                //both admin inject and receiver object exist
                if(this.admin_injected_count + this.receiver_objects.length >= 1){
                    return true;
                } else {
                    return false;
                }
            } else {
                //only admin inject
                if(this.admin_injected_count > 0){
                    return true;
                } else {
                    return false;
                }
            }
        } else{
            if(this.receiver_objects){
                //only receiver object
                if(this.receiver_objects.length >= 1){
                    return true;
                } else {
                    return false;
                }
            } else {
                return false;
                //both doesnt exist
            }
        }
    },
    date:{
        "$lte":new Date("2019-07-01T00:00:00.000Z")
    }
},
{ 
    sender_id: 1
})
.toArray()



// unlocked in july or later: 1 month left 
[{"expire": 1569062051, "metadata": {"reply_remaining": 100}, "permission": "jobpool_reply"}, {"expire": 1569062051, "permission": "jobpool_instant_new_job_notify"}, {"expire": 1569062051, "permission": "jobpool_new_job_email"}, {"expire": 1569062051, "permission": "jobpool_job_record"}, {"expire": 1569062051, "permission": "jobpool_advance_filter"}, {"expire": 1569062051, "metadata": {"cancel": 1566384256, "premium_type": "plus"}, "permission": "premium_ac"}]

db.getCollection('referrals')
.find({
    $where:function() {
        if(this.admin_injected_count){
            if(this.receiver_objects){
                //both admin inject and receiver object exist
                if(this.admin_injected_count + this.receiver_objects.length >= 1){
                    return true;
                } else {
                    return false;
                }
            } else {
                //only admin inject
                if(this.admin_injected_count > 0){
                    return true;
                } else {
                    return false;
                }
            }
        } else{
            if(this.receiver_objects){
                //only receiver object
                if(this.receiver_objects.length >= 1){
                    return true;
                } else {
                    return false;
                }
            } else {
                return false;
                //both doesnt exist
            }
        }
    },
    date:{
        "$gt":new Date("2019-07-01T00:00:00.000Z")
    }
},
{ 
    sender_id: 1
})
.toArray()
    
// -if purchase plus plan jau will automatically add 7 more days to them 
// -system needs to be able to auto lock 返job pool after the days expire