1

I have this levels in mongoose documents enter image description here

I'm trying to make a filter to populate the geometry for the locations that are in the range of some date.

I try something like this:

.populate('geometries', null, { 'locations.properties.timeStamp': { $gt: startDate, $lt: endDate }})
.exec(function(err, item) {
//some code
}

And like this:

 .populate('geometries')
 .where({ 'locations.properties.timeStamp': { $gt: startDate, $lt: endDate }}*/)
 .exec(function(err, item) {
    //some code
    }

With these query I can not access the timeStamp to compare, and the result is null or undefined.

EDIT 1:

The variables, startDate and endDate comes in the url from angulars controller, they are defined like this:

            var deductDate = new Date(endDate);
            var startDate = deductDate.setDate(deductDate.getDate()-1);

            Item.currentDay($stateParams.epc, url, {
                groupBy: '1d',
                endDate: moment(endDate).format(),
                startDate: moment(startDate).format('YYYY-MM-DD') + "T23:59:59"
            });

And in the API the GET route that handles that is:

 handler: function(request, reply) {
  var startDate = request.query.startDate;
  var endDate = request.query.endDate;
  Item.findById(request.params.id)
    .populate('geometries', null, { 'locations.properties.timeStamp': { $gt: startDate, $lt: endDate }})
    .exec(function(err, item) {
      if (err) {
        reply(err);
      } else {
        reply(item);
      }
    });
}
2
  • Show us where you're defining startDate and endDate Commented Mar 12, 2015 at 2:52
  • Thanks for your answer @YuriZarubin, in the original post a add what you ask. Commented Mar 12, 2015 at 3:07

2 Answers 2

1

Try to do this:

.populate({
  path: 'geometries',
  match: { 'locations.properties.timeStamp': { $gt: startDate, $lt: endDate    }},
}).exec()

Extracted from mongoose documentation about Query conditions and other options (http://mongoosejs.com/docs/populate.html)

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks scuencag, but still not working, the console.log shows null value. This are te format of the days that I'm using to do the search: startDate: 2015-03-13T23:59:59, endDate: 2015-03-14T19:47:37-03:00. Are they ok?
0

Do this:

  var startDate = new Date(request.query.startDate);
  var endDate = new Date(request.query.endDate);

3 Comments

with that the filter still don't work, is 'locations.properties.timeStamp' correct to acces timeStamp to use the date filter?
Looks right. Try doing a simple test such as: populate('geometries', null, { 'locations.properties.timeStamp': { $gt: new Date('2015-05-10') }})
I make that test but the filter not work, returns a null value.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.