1

I have a function that creates a query object for me based on a number of conditions:

compileSearchCriteria(search){
        var conditions = {
            published: true
        };
        conditions["publishedDate"] = {$lte: new Date(search.searchDate)};

        <more code here>

        return conditions;
    },

Dates are stored as ISODates in MongoDB. The resulting query looks like this:

{"published":true,"publishedDate":{"$lte":"2016-03-27T16:23:12.000Z"}}

and returns nothing.

db.trips.find({"published":true,"publishedDate":{"$lt":ISODate("2016-03-27T15:48:41.866Z")}})

returns desired results. Sending the query direct works as well:

DealsCollection.find({published:true, publishedDate:{$lt: new Date(this.props.searchDate)}}).fetch()

How can I create the query object so that I get proper results?

Update It should work and it does work. The problem seems to be with mini-mongo implementation in Meteor. I separated the calls to see where the disconnect is. The server returned data using the original query. But querying resulting documents from the mini-mongo collection produced no results, even though I can see returned documents in it. That is a different issue. Thank you for pointers.

Alex Polkhovsky
  • 3,340
  • 5
  • 29
  • 37
  • 1
    it probably wrong syntax it should work –  Mar 27 '16 at 17:59
  • `db.trips.find({"published":true,"publishedDate":{"$lt":"2016-03-27T15:48:41.866Z"}})` produces no results in mongo shell. `db.trips.find({"published":true,"publishedDate":{"$lt":ISODate("2016-03-27T15:48:41.866Z")}})` produces results. – Alex Polkhovsky Mar 27 '16 at 18:02
  • I usually use a date object and not ISOString, it will get auto converted by mongo also try to use `$lte` so if it's the same date it will detect it for example: `var date = new Date();` `db.trips.find({"published":true,"publishedDate":{"$lte": date }})` and you can modify the date date with `date.setUTCDate` –  Mar 27 '16 at 18:09

0 Answers0