Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I add a filter by date option to the query? #9

Open
bluerid opened this issue Mar 8, 2018 · 1 comment
Open

How do I add a filter by date option to the query? #9

bluerid opened this issue Mar 8, 2018 · 1 comment

Comments

@bluerid
Copy link

bluerid commented Mar 8, 2018

I need to send in a date range to filter docs returning list of events date wise. How would I be able to do this? Sending the filter parameter with {params} doesn't do anything.

params.date_event = {
      "$gte": _startdate,
      "$lt": _enddate
}
       Event.paginate(params, '_id')
          .execPagination(function(err, events) {
            if(err)
              res.send(err)

              if(events.results.length){
                var dates = []
                var results = []
                events.results.forEach((current) => {
                  var currentDate = current['date_event'].split('T')[0]
                  if(!dates.includes(currentDate)){
                    dates.push(currentDate);
                    results.push ({
                      date: currentDate,
                      items: []
                    });
                  }
                  var dateIdx = dates.indexOf(currentDate)
                  results[dateIdx].items.push(current)
                })
                events.results = results
              }
              res.json({message: "Retrieved Events", events: events})
        });
@resistancecanyon
Copy link

resistancecanyon commented Apr 23, 2018

@bluerid
You could easily add a where clause like this, just like you run it over a mongoose query.
Remember this is a mongoose plugin 😄
Like so below
filter.date_event = { "$gte": _startdate, "$lt": _enddate }
paginationParams = { after: "52fb4cd4205626aceddc7127" };
Event.paginate(paginationParams, '_id') .where(filter) .execPagination(function(err, events) { //your stuff here })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants